Documentation
¶
Overview ¶
Usage
Create API by NewAPI and call it's methods. See more about usage in NewAPI's docs.
You have two ways of using API. First is by calling API's method:
swiftAPI := swift.NewAPI(...) swiftAPI.GetBicDetails(ctx, bic)
This way is more convenient and less verbose. In most cases that's enough, but by using this approach you can provide only required arguments in SWIFT API. If you need to provide optional arguments you can use second way:
swiftAPI := swift.NewAPI(...) optionalArgs := swiftref.BicsApiGetBicDetailsV2Opts{APIStatus: optional.NewString("APIStatus")} swiftAPI.Reference.BicsApi.GetBicDetailsV2(swiftAPI.WithContext(ctx, swiftref.ContextOAuth2), bic, &optionalArgs)
More verbose, but now you can specify optional arguments to SWIFT API. See more about this approach in API.WithContext docs.
Index ¶
- Constants
- Variables
- func NewErrWithHTTPResponse(HTTPResponse *http.Response, err error) error
- func NotFound(err error) bool
- func UnAuthorized(err error) bool
- func ValidateBic(anyBic string) error
- func ValidateBicFi(bicFi string) error
- func ValidateCountryCode(countryCode string) error
- func ValidateCreditorAccount(creditorAccount string) error
- func ValidateCreditorName(creditorAccount string) error
- type API
- func (api *API) BankingAnalytics(ctx context.Context, code analytics.Market1Code, reportingPeriod string) (*analytics.InlineResponse200, error)
- func (api *API) GetAccountNumberValidity(ctx context.Context, accountNumber string) (*swiftref.InlineResponse20021, error)
- func (api *API) GetAuthToken(ctx context.Context) (*AuthenticationToken, error)
- func (api *API) GetBicDetails(ctx context.Context, BIC string) (*swiftref.InlineResponse2005, error)
- func (api *API) GetBicFromIban(ctx context.Context, iban string) (*swiftref.InlineResponse2001, error)
- func (api *API) GetBicFromIbanNationalId(ctx context.Context, ibanNationalID, countryCode string) (*swiftref.InlineResponse2003, error)
- func (api *API) GetBicFromLei(ctx context.Context, lei string) (*swiftref.InlineResponse2008, error)
- func (api *API) GetBicValidity(ctx context.Context, BIC string) (*swiftref.InlineResponse2006, error)
- func (api *API) GetBicsFromNationalId(ctx context.Context, nationalID string) (*swiftref.InlineResponse20014, error)
- func (api *API) GetCountryCodeDetails(ctx context.Context, countryCode string) (*swiftref.InlineResponse20016, error)
- func (api *API) GetCountryCodeValidity(ctx context.Context, countryCode string) (*swiftref.InlineResponse20015, error)
- func (api *API) GetCurrencyCodeDetails(ctx context.Context, countryCode string) (*swiftref.InlineResponse20018, error)
- func (api *API) GetCurrencyCodeValidity(ctx context.Context, currencyCode string) (*swiftref.InlineResponse20017, error)
- func (api *API) GetIbanDetails(ctx context.Context, iban string) (*swiftref.InlineResponse2002, error)
- func (api *API) GetIbanFromBban(ctx context.Context, BBAN, countryCode string) (*swiftref.InlineResponse2004, error)
- func (api *API) GetIbanValidity(ctx context.Context, iban string) (*swiftref.InlineResponse200, error)
- func (api *API) GetLeiDetails(ctx context.Context, lei string) (*swiftref.InlineResponse20020, error)
- func (api *API) GetLeiFromBic(ctx context.Context, BIC string) (*swiftref.InlineResponse2007, error)
- func (api *API) GetLeiValidity(ctx context.Context, lei string) (*swiftref.InlineResponse20019, error)
- func (api *API) GetNationalIdDetails(ctx context.Context, nationalID string) (*swiftref.InlineResponse20012, error)
- func (api *API) GetNationalIdValidity(ctx context.Context, nationalID string) (*swiftref.InlineResponse20013, error)
- func (api *API) GetNationalIdsFromBic(ctx context.Context, BIC string) (*swiftref.InlineResponse2009, error)
- func (api *API) GetSepaReachabilityFromBic(ctx context.Context, BIC, sepaScheme string) (*swiftref.InlineResponse20010, error)
- func (api *API) GetSsisFromBic(ctx context.Context, BIC, currencyCode string) (*swiftref.InlineResponse20011, error)
- func (api *API) RefreshAuthToken(ctx context.Context) (*AuthenticationToken, error)
- func (api *API) RevokeAuthToken(ctx context.Context) error
- func (api *API) Token() (*oauth2.Token, error)
- func (api *API) WithContext(ctx context.Context, key interface{}) context.Context
- type AppCredentials
- type AuthenticationToken
- type ErrWithHTTPResponse
- type Option
Examples ¶
Constants ¶
const ( // Sandbox is a testing environment, but can be used in production for some services // from docs: ... KYC Registry API, Banking Analytics API, Banking Premium API and Compliance Analytics API, Sandbox CAN be used for UAT. Sandbox = env(iota) // Production is a production environment Production )
Variables ¶
var ( ErrInvalidAnyBic = errors.New("bic number is not valid") ErrCreditorAccountLengthOutOfRange = errors.New("credit account length out of 1 to 34 range") ErrCreditorNameLengthOutOfRange = errors.New("credit name length out of 1 to 140 range") ErrInvalidCountryCode = errors.New("county code must contain only 2 uppercase symbols") )
Functions ¶
func NewErrWithHTTPResponse ¶
func UnAuthorized ¶ added in v0.3.0
func ValidateBic ¶
ValidateBic - validates BIC format BIC - code allocated to a financial or non-financial institution by the ISO 9362 Registration Authority
func ValidateCountryCode ¶
ValidateCountryCode - ISO 3166, Alpha-2 code
func ValidateCreditorAccount ¶
ValidateCreditorAccount - strings, between 1 and 34 chars
func ValidateCreditorName ¶
ValidateCreditorName - strings, between 1 and 140 chars
Types ¶
type API ¶
type API struct { Reference *swiftref.APIClient Analytics *analytics.APIClient PreValidation *prevalidation.APIClient // contains filtered or unexported fields }
API aggregates swiftref, bank-analytics APIs and deals with authentication (gets access token as needed)
func NewAPI ¶
func NewAPI(environment env, credentials AppCredentials, options ...Option) *API
NewAPI return new API based on given args and options
Example ¶
package main import ( "context" "github.com/alifcapital/swift" "log" "net/http" ) func main() { swiftAPI := swift.NewAPI(swift.Sandbox, swift.AppCredentials{ BasicAuthUser: "some_user", BasicAuthPass: "some_pass", Username: "some_username", Password: "some_password", }, swift.HTTPClient(http.DefaultClient)) bicDetails, err := swiftAPI.GetBicDetails(context.Background(), "DEUTDEFF") if err != nil { switch { case swift.NotFound(err): log.Println("no such bic") case swift.UnAuthorized(err): log.Println("unauthorized") default: log.Println("getting bic details:", err) } return } _ = bicDetails }
Output:
func (*API) BankingAnalytics ¶
func (api *API) BankingAnalytics(ctx context.Context, code analytics.Market1Code, reportingPeriod string) (*analytics.InlineResponse200, error)
func (*API) GetAccountNumberValidity ¶
func (*API) GetAuthToken ¶
func (api *API) GetAuthToken(ctx context.Context) (*AuthenticationToken, error)
GetAuthToken fetches from SWIFT api new `AuthenticationToken`. https://developer.swift.com/oauth-reference#section/Authentication/clientAuth
CAUTION: getting new access token invalidates previous one, so DO NOT use it when you are using API methods for SWIFT-API. Getting new access tokens by need is managed automatically by API.
func (*API) GetBicDetails ¶
func (*API) GetBicFromIban ¶
func (*API) GetBicFromIbanNationalId ¶
func (*API) GetBicFromLei ¶
func (*API) GetBicValidity ¶
func (*API) GetBicsFromNationalId ¶
func (*API) GetCountryCodeDetails ¶
func (*API) GetCountryCodeValidity ¶
func (*API) GetCurrencyCodeDetails ¶
func (*API) GetCurrencyCodeValidity ¶
func (*API) GetIbanDetails ¶
func (*API) GetIbanFromBban ¶
func (*API) GetIbanValidity ¶
func (*API) GetLeiDetails ¶
func (*API) GetLeiFromBic ¶
func (*API) GetLeiValidity ¶
func (*API) GetNationalIdDetails ¶
func (*API) GetNationalIdValidity ¶
func (*API) GetNationalIdsFromBic ¶
func (*API) GetSepaReachabilityFromBic ¶
func (*API) GetSsisFromBic ¶
func (*API) RefreshAuthToken ¶
func (api *API) RefreshAuthToken(ctx context.Context) (*AuthenticationToken, error)
RefreshAuthToken fetches from SWIFT api new `AuthenticationToken`. https://developer.swift.com/oauth-reference#section/Authentication/clientAuth
func (*API) RevokeAuthToken ¶
RevokeAuthToken removes/disposes authentication tokens. https://developer.swift.com/oauth-reference#operation/revokeAccessToken
func (*API) WithContext ¶
WithContext wraps ctx with authentication information.
Example ¶
package main import ( "context" "github.com/alifcapital/swift" "github.com/alifcapital/swift/swagger/swift/analytics" "github.com/alifcapital/swift/swagger/swift/swiftref" "github.com/antihax/optional" ) func main() { // swiftref: swiftAPI := swift.NewAPI(swift.Sandbox, swift.AppCredentials{ BasicAuthUser: "some_user", BasicAuthPass: "some_pass", Username: "some_username", Password: "some_password", }) ctx := context.Background() bicDetails, httpResponse, err := swiftAPI.Reference.BicsApi. GetBicDetailsV2(swiftAPI.WithContext(ctx, swiftref.ContextOAuth2), "DEUTDEFF", nil) if err != nil { // ... } _, _ = bicDetails, httpResponse // bank analytics: bankingAnalyticsOpts := analytics.BankingAnalyticsApiBankingAnalyticsOpts{ Limit: optional.NewInterface(10), Offset: optional.NewInterface(0), } bankingAnalytics, httpResponse, err := swiftAPI.Analytics.BankingAnalyticsApi. BankingAnalytics(swiftAPI.WithContext(ctx, analytics.ContextOAuth2), "PMTS_payments", "2018-08", &bankingAnalyticsOpts) if err != nil { // ... } _, _ = bankingAnalytics, httpResponse }
Output:
type AppCredentials ¶
type AppCredentials struct { BasicAuthUser string // consumer_key BasicAuthPass string // consumer_secret Username string // license_id Password string // license_key }
AppCredentials is a credentials to make OAuth2 request
type AuthenticationToken ¶
type AuthenticationToken struct { AccessToken string `json:"access_token"` ExpiresIn string `json:"expires_in"` RefreshToken string `json:"refresh_token"` RefreshTokenExpiresIn string `json:"refresh_token_expires_in"` TokenType string `json:"token_type"` }
AuthenticationToken returned after successful authentication `AccessToken` used in http Authorization headers `ExpiresIn` by default is 1800-1 seconds (30min) `RefreshToken` used for requiring new AuthenticationToken and is alive for 86400-1 seconds (1 day) `TokenType` is a part of Authorization header: ex. req.Header.Set("Authorization", "Bearer "+t.AuthenticationToken
It is strongly recommended that your application dispose tokens that are no longer needed. SWIFT will invalidate the tokens from further use if you do. Once invalidated, they can no longer be used to access SWIFT APIs.
type ErrWithHTTPResponse ¶
func (*ErrWithHTTPResponse) Error ¶
func (e *ErrWithHTTPResponse) Error() string
func (*ErrWithHTTPResponse) NotFound ¶
func (e *ErrWithHTTPResponse) NotFound() bool
func (*ErrWithHTTPResponse) UnAuthorized ¶ added in v0.3.0
func (e *ErrWithHTTPResponse) UnAuthorized() bool
func (*ErrWithHTTPResponse) Unwrap ¶
func (e *ErrWithHTTPResponse) Unwrap() error
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
swagger
|
|
swift/analytics
* SWIFT Banking Analytics * * SWIFT Watch Banking Analytics API enables institutions to retrieve their own SWIFT traffic data and the SWIFT totals, extending to the level of value and currency per market.
|
* SWIFT Banking Analytics * * SWIFT Watch Banking Analytics API enables institutions to retrieve their own SWIFT traffic data and the SWIFT totals, extending to the level of value and currency per market. |
swift/prevalidation
* Payment Pre-validation API * * New version of the Bank Account Verification Service (the BAV), BAV v2, for Users and Data Providers.
|
* Payment Pre-validation API * * New version of the Bank Account Verification Service (the BAV), BAV v2, for Users and Data Providers. |
swift/swiftref
* SWIFTRef API * * SWIFTRef API * * API version: 1.6.0 * Contact: developer-support@swift.com * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
* SWIFTRef API * * SWIFTRef API * * API version: 1.6.0 * Contact: developer-support@swift.com * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) |