You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is comprehensive usage document for this library
1. Customers
Request
client:=NewClient(apiKey, nil)
cust:=&Customer{
FamilyName: "Oyewale",
GivenName: "Ademola",
Email: "user123@gmail.com",
PostalCode: "E2 8DP",
CountryCode: "GB",
City: "Lagos",
AddressLine1: "Just somewhere on Earth",
AddressLine2: "Another place on Earth",
AddressLine3: "Just the third address to justify things",
Language: "en",
}
// create the customerclient.LoggingEnabled=truecustomer, err:=client.Customer.Create(cust)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a customer is :%s", err.Error())
}
fmt.Sprintf("The customer created is: %s ", string(customer.Email))
// Get customer by IDcustomer, err=client.Customer.Get(customer.ID)
iferr!=nil {
fmt.Sprintf("The error while getting a customer is :%s", err.Error())
}
fmt.Sprintf("The customer retrieved with ID: %d is : %s", customer.ID, customer.Email)
// listing all customerscustomerReq:=&CustomerListRequest{
Limit: 100,
}
// list all customers_, err:=client.Customer.ListAllCustomers(customerReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of customers is :%s", err.Error())
}
Response
2017/09/02 20:50:14 Requesting GET api-sandbox.gocardless.com/customers/
{"customers":{"id":"CU00029EH0FGEB","created_at":"2017-09-02T19:50:14.085Z","email":"user123@gmail.com","given_name":"Ademola","family_name":"Oyewale","company_name":null,"address_line1":"Just somewhere on Earth","address_line2":"Another place on Earth","address_line3":"Just the third address to justify things","city":"Lagos","region":null,"postal_code":"E2 8DP","country_code":"GB","language":"en","swedish_identity_number":null,"metadata":{}}}The call method is being called2017/09/02 20:50:15 Completed in 557.343235msRESPONSE https://api-sandbox.gocardless.com/customers/
{"customers":[{"id":"CU00029EH0FGEB","created_at":"2017-09-02T19:50:14.085Z","email":"user123@gmail.com","given_name":"Ademola","family_name":"Oyewale","company_name":null,"address_line1":"Just somewhere on Earth","address_line2":"Another place on Earth","address_line3":"Just the third address to justify things","city":"Lagos","region":null,"postal_code":"E2 8DP","country_code":"GB","language":"en","swedish_identity_number":null,"metadata":{}},{"id":"CU00029BQFAY9V","created_at":"2017-09-01T19:22:25.107Z","email":"user123@gmail.com","given_name":"Ademola","family_name":"Oyewale","company_name":null,"address_line1":"Just somewhere on Earth","address_line2":"Another place on Earth","address_line3":"Just the third address to justify things","city":"Lagos","region":null,"postal_code":"E2 8DP","country_code":"GB","language":"en","swedish_identity_number":null,"metadata":{}}],"meta":{"cursors":{"before":null,"after":null},"limit":50}}
2. Creditors
Request
client:=NewClient(apiKey, nil)
cust:=&Creditor{
Name: "Oyewale",
PostalCode: "E2 8DP",
CountryCode: "GB",
City: "Lagos",
AddressLine1: "Just somewhere on Earth",
AddressLine2: "Another place on Earth",
AddressLine3: "Just the third address to justify things",
}
// create the creditorclient.LoggingEnabled=truecustomer, err:=client.Creditor.CreateCreditor(cust)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a creditor is :%s", err.Error())
}
fmt.Sprintf("The creditor created is: %s ", string(customer.Name))
// Get creditor by IDcustomer, err=client.Creditor.GetCreditor(customer.Id)
iferr!=nil {
fmt.Sprintf("The error while getting a creditor is :%s", err.Error())
}
fmt.Sprintf("The creditor retrieved with ID: %d is : %s", customer.Id, customer.Name)
creditorUpdated:=&Creditor{
Id: customer.Id,
Name: "Oyewale Sao",
PostalCode: "E2 8DP",
CountryCode: "GB",
City: "Lagos",
AddressLine1: "Just somewhere on Earth",
AddressLine2: "Another place on Earth",
AddressLine3: "Just the third address to justify things",
}
// updatex the creditorclient.LoggingEnabled=truecreditor, err=client.Creditor.UpdateCreditor(creditorUpdated)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while updating a creditor is :%s", err.Error())
}
fmt.Sprintf("The creditor updated is: %s ", string(creditor.Name))
//list all creditorscreditorListReq:=&CreditorListRequest{
Limit: 100,
}
// list all creditors_, err:=client.Creditor.ListCreditors(creditorListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of creditors is :%s", err.Error())
}
client:=NewClient(apiKey, nil)
acct:=&CustomerBankAccountCreateRequest{
BankCode: "Oyewale",
Currency: "PND",
BranchCode: "LEI",
AccountNumber: "03434",
CountryCode: "GB",
}
// create a customer bank accountclient.LoggingEnabled=trueaccount, err:=client.CustomerBankAccount.CreateCustomerBankAccount(acct)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a customer bank account is :%s", err.Error())
}
fmt.Sprintf("The customer bank account created is: %s ", account.BankName)
// Get customer bank Account by IDaccount, err=client.CustomerBankAccount.GetCustomerBankAccount(account.Id)
iferr!=nil {
fmt.Sprintf("The error while getting a customer bank account is :%s", err.Error())
}
fmt.Sprintf("The customer bank account retrieved with ID: %d is : %s", account.Id, account.BankName)
custBankAccountUpdate:=&CustomerBankAccount{
BankName: "Oyewale",
AccountHolderName: "Ademola",
CountryCode: "GB",
}
account, err=client.CustomerBankAccount.UpdateCustomerBankAccount(custBankAccountUpdate, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while updating a customer bank account is :%s", err.Error())
}
fmt.Sprintf("The customer bank account updated is: %s ", account.BankName)
//list all customers bank accountscustomerBankAccountListReq:=&CustomerBankListRequest{
Limit: 100,
}
// list all customers bank accounts_, err:=client.CustomerBankAccount.ListCustomerBankAccounts(customerBankAccountListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of customers bank accounts is :%s", err.Error())
}
4. Creditor Bank Account
Making request
client:=NewClient(apiKey, nil)
acct:=&CreditorBankAccountCreateRequest{
BankCode: "Oyewale",
Currency: "PND",
BranchCode: "LEI",
AccountNumber: "03434",
CountryCode: "GB",
}
// create a creditor bank accountclient.LoggingEnabled=trueaccount, err:=client.CreditorBankAccount.CreateCreditorBankAccount(acct)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a creditor bank account is :%s", err.Error())
}
fmt.Sprintf("The creditor bank account created is: %s ", account.BankName)
// Get creditor bank Account by IDaccount, err=client.CreditorBankAccount.GetCreditorBankAccount(account.Id)
iferr!=nil {
fmt.Sprintf("The error while getting a creditor bank account is :%s", err.Error())
}
fmt.Sprintf("The creditor bank account retrieved with ID: %d is : %s", account.Id, account.BankName)
//listing all creditors bank accountscreditorBankAccountListReq:=&CreditorBankAccountListRequest{
Limit: 100,
}
// list all creditors bank accounts_, err:=client.CreditorBankAccount.ListCreditorBankAccounts(creditorBankAccountListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of creditors bank accounts is :%s", err.Error())
}
5. Bank Details Lookup
Making the request
client:=NewClient(apiKey, nil)
bankLookup:=&BankDetailsLookupRequest{
AccountNumber: "55779911",
BranchCode: "200000",
CountryCode: "GB",
}
account, err:=client.BankDetailsLookup.Lookup(bankLookup)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while looking up details of a bank is :%s", err.Error())
}
fmt.Sprintf("The customer bank account updated is: %s ", account)
Response
2017/09/02 22:03:42 Requesting POST api-sandbox.gocardless.com/bank_details_lookups2017/09/02 22:03:46 Completed in 4.495158108sRESPONSE https://api-sandbox.gocardless.com/bank_details_lookups
{"bank_details_lookups":{"bank_name":"BARCLAYS BANK PLC","available_debit_schemes":["bacs"],"bic":"BUKBGB22XXX"}}
6. Events
Making Request
client:=NewClient(apiKey, nil)
event, err:=client.Event.GetEvent("EV123")
iferr!=nil {
fmt.Sprintf("The error while getting an event is :%s", err.Error())
}
fmt.Sprintf("The event retrieved with ID: %d is : %s", event.ID, event.Details)
//Getting a list of eventseventsListReq:=&EventListRequest{
Limit: 100,
}
// list all events_, err:=client.Event.ListEvents(eventsListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of events is :%s", err.Error())
}
7. Mandate
Making Request
//second param is an optional http client, allowing overriding of the HTTP client to use.//This is useful if you're running in a Google AppEngine environment//where the http.DefaultClient is not available.client:=NewClient(apiKey, nil)
linksMap:=map[string]string{
"customer_bank_account": "XXXX",
}
linksMapString, _:=json.Marshal(linksMap)
linksJson:=string(linksMapString[:])
rel:=map[string]string{
"links": linksJson,
}
linksString, _:=json.Marshal(rel)
linkJson:=string(linksString[:])
linkJson,_=strconv.Unquote(linkJson)
mandateReq:=&MandateCreateRequest{
Scheme: "bacs",
Links: linkJson,
CustomerBankAccount: "MD123",
}
// create a mandateclient.LoggingEnabled=truemandate, err:=client.Mandate.CreateMandate(mandateReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a mandate is :%s", err.Error())
}
fmt.Sprintf("The mandate created is: %s ", mandate.Scheme)
// Get mandate by IDmandate, err=client.Mandate.GetMandate("MD123")
iferr!=nil {
fmt.Sprintf("The error while getting a mandate is :%s", err.Error())
}
fmt.Sprintf("The event retrieved with ID: %d is : %s", mandate.ID, mandate.Scheme)
mandateUpdateReq:=&Mandate{
Reference: "New reference",
Scheme: "bacs",
}
// update a mandateclient.LoggingEnabled=truemandateToUpdate, err:=client.Mandate.UpdateMandate(mandateUpdateReq, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while updating a mandate is :%s", err.Error())
}
fmt.Sprintf("The mandate updated is: %s ", mandateToUpdate.Reference)
// cancel a mandatemandateCancelReq:=&Mandate{
Reference: "New reference",
Scheme: "bacs",
ID: "MD123",
}
client.LoggingEnabled=truemandateToCancel, err:=client.Mandate.CancelMandate(mandateCancelReq, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while canceling a mandate is :%s", err.Error())
}
fmt.Sprintf("The mandate canceled returned the response: %s ", mandateToCancel)
// reinstate a mandatemandateReinReq:=&Mandate{
Reference: "New reference",
Scheme: "bacs",
ID: "MD123",
}
client.LoggingEnabled=truemandateToRein, err:=client.Mandate.ReinstateMandate(mandateReinReq, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while reinstating a mandate is :%s", err.Error())
}
fmt.Sprintf("The mandate reinstated returned a response: %s ", mandateToRein)
// list all mandatesmandateListReq:=&MandateListRequest{
Limit: 100,
}
// list all mandates_, err:=client.Mandate.ListNMandates(mandateListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of mandates is :%s", err.Error())
}
8. Mandate PDFs
Making the request
client:=NewClient(apiKey, nil)
linkMap:=make(map[string]string)
linkMap["mandate"] ="MD123"mandateReq:=&MandatePdfCreateRequest{
Links: linkMap,
}
// create a mandateclient.LoggingEnabled=truemandate, err:=client.MandatePdf.CreateMandatePdf(mandateReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a mandate pdf is :%s", err.Error())
}
fmt.Sprintf("The mandate pdf created is: %s ", mandate.Url)
9. Payouts
Making the request
// Get Payout by IDpayout, err:=client.Payout.GetPayout("PO123")
iferr!=nil {
fmt.Sprintf("The error while getting a payout is :%s", err.Error())
}
fmt.Sprintf("The payout retrieved with ID: %d is : %s", payout.ID, payout.Reference)
// list all payoutspayoutsListReq:=&PayoutListRequest{
Limit: 100,
}
// list all payouts_, err:=client.Payout.ListPayouts(payoutsListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of payouts is :%s", err.Error())
}
10. Redirect Flows
Making the request
client:=NewClient(apiKey, nil)
rFlowCreateReq:=&RedirectFlowCreateRequest{
Description: "Wine vines",
SessionToken: "SESS_wSs0uGYMISxzqOBq",
PrefilledCustomer: PrefilledCustomer{
GivenName: "Ademola",
FamilyName: "Oyewale",
},
SuccessRedirectUrl: "https://wewee.ngrok.io/",
}
// create a redirecflowclient.LoggingEnabled=trueredirectFlow, err:=client.RedirectFlow.Create(rFlowCreateReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a redirect flow pdf is :%s", err.Error())
}
fmt.Sprintf("The redirect flow created has the description: %s ", redirectFlow.Description)
// Get Redirect Flow by IDrFlow, err:=client.RedirectFlow.GetRedirectFlow("RE123")
iferr!=nil {
fmt.Sprintf("The error while getting a redirect flow is :%s", err.Error())
}
fmt.Sprintf("The redirecte flow retrieved with ID: %d is : %s", rFlow.ID, rFlow.Description)
rFlowCompleteReq:=&RedirectFlowCompleteRequest{
SessionToken: "SESS_wSs0uGYMISxzqOBq",
}
// complete a redirecflowclient.LoggingEnabled=trueredFlow, err:=client.RedirectFlow.CompleteRedirectFlow("RE123", rFlowCompleteReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while completing a redirect flow pdf is :%s", err.Error())
}
fmt.Sprintf("The redirect flow completed has the description: %s ", redFlow)
refundCreateReq:=&RefundCreateRequest{
Amount: 100,
TotalAmountConfirmation: "200",
Links: map[string]string{
"payment":"PM123",
},
}
// create a refundclient.LoggingEnabled=truerefund, err:=client.Refund.CreateRefund(refundCreateReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a refund :%s", err.Error())
}
fmt.Sprintf("The refund created has the reference: %s ", refund.Reference)
// Get Refund by IDrefund, err=client.Refund.GetRefund("RF123")
iferr!=nil {
fmt.Sprintf("The error while getting a refund is :%s", err.Error())
}
fmt.Sprintf("The refund retrieved with ID: %d is : %s", refund.ID, refund.Reference)
refundUpdateReq:=&Refund{
Reference: "New reference",
Amount: 10,
}
// update a refundclient.LoggingEnabled=truerefundToUpdate, err:=client.Refund.UpdateRefund(refundUpdateReq, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while updating a refund is :%s", err.Error())
}
fmt.Sprintf("The refund updated is: %s ", refundToUpdate.Reference)
12. Subscriptions
Making the request
subCreateReq:=&SubscriptionCreateRequest{
Amount: 100,
Currency: "GBP",
IntervalUnit: "monthly",
}
// create a subscriptionclient.LoggingEnabled=truesubscription, err:=client.Subscription.CreateSubscription(subCreateReq)
iferr!=nil {
// do something with errorfmt.Sprintf("The error while creating a subscription :%s", err.Error())
}
fmt.Sprintf("The subscription created has the ID: %s ", subscription.ID)
// Get Subscription by IDsubscription, err=client.Subscription.GetSubscription("SB123")
iferr!=nil {
fmt.Sprintf("The error while getting a subscription is :%s", err.Error())
}
fmt.Sprintf("The subscription retrieved with ID: %d is : %s", subscription.ID, subscription.Name)
subUpdateReq:=&Subscription{
Amount: 10,
}
// update a refundclient.LoggingEnabled=truesubToUpdate, err:=client.Subscription.UpdateSubscription(subUpdateReq, "sample", "SB123", make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while updating a subscription is :%s", err.Error())
}
fmt.Sprintf("The subscription updated is: %s ", subToUpdate.Name)
// cancel a mandatesubCancelReq:=&Subscription{
Metadata: map[string]string{
"order_no": "ABCD1234",
},
}
client.LoggingEnabled=truesubToCancel, err:=client.Subscription.CancelSubscription(subCancelReq, make(map[string]string))
iferr!=nil {
// do something with errorfmt.Sprintf("The error while canceling a subscription is :%s", err.Error())
}
fmt.Sprintf("The subscription canceled returned the response: %s ", subToCancel)
//list all subscriptionssubscriptionsListReq:=&SubscriptionListRequest{
Limit: 100,
}
// list all subscriptions_, err:=client.Subscription.ListSubscriptions(subscriptionsListReq)
iferr!=nil {
fmt.Sprintf("The error while getting list of subscriptions is :%s", err.Error())
}