Skip to content
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,22 @@ The client allows you to validate that a webhook you receive is genuinely from G
func parseEvents(event Event) {
// work through list of events
}
```
```

#### Accessing the webhook ID

If you need to access the webhook ID for debugging purposes, you can use `ParseWebhook` to get both the events and webhook metadata:

```go
result, err := gocardless.ParseWebhook(requestBody, signatureHeader, webhookEndpointSecret)
if err != nil {
// Handle invalid signature error
}
events := result.Events
webhookId := result.WebhookId // e.g. "WB123" - useful for debugging
```

Note: The webhook ID is intended for debugging and logging purposes only. It should not be used for deduplication - instead, use the event IDs to deduplicate, as each event has a unique ID that remains consistent if the same event is sent multiple times.

### Error Handling

Expand Down
30 changes: 30 additions & 0 deletions code_sample_tests/balance_code_samples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBalanceListCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("balances", true)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

params := gocardless.BalanceListParams{
Creditor: "CR123",
}

response, err := client.Balances.List(ctx, params)

}
35 changes: 35 additions & 0 deletions code_sample_tests/bank_account_detail_code_samples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBankAccountDetailGetCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_account_details", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

headers := map[string]string{
"Gc-Key-Id": "PK123",
}

bankAccountDetails, err := client.BankAccountDetails.Get(
ctx,
"BA123",
gocardless.BankAccountDetailGetParams{},
gocardless.WithHeaders(headers),
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBankAccountHolderVerificationCreateCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_account_holder_verifications", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

bankAccountHolderVerificationCreateParams := gocardless.BankAccountHolderVerificationCreateParams{
Type: "confirmation_of_payee",
Links: gocardless.BankAccountHolderVerificationCreateParamsLinks{
BankAccount: "BA123",
},
}

verification, err := client.BankAccountHolderVerifications.Create(ctx, bankAccountHolderVerificationCreateParams)

}

func TestBankAccountHolderVerificationGetCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_account_holder_verifications", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

verification, err := client.BankAccountHolderVerifications.Get(ctx, "BAHV123")

}
44 changes: 44 additions & 0 deletions code_sample_tests/bank_authorisation_code_samples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBankAuthorisationCreateCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_authorisations", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

bankAuthorisationCreateParams := gocardless.BankAuthorisationCreateParams{
RedirectUri: "https://my-company.com/landing",
Links: gocardless.BankAuthorisationCreateParamsLinks{
BillingRequest: "BR123",
},
}

bankAuthorisation, err := client.BankAuthorisations.Create(ctx, bankAuthorisationCreateParams)

}

func TestBankAuthorisationGetCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_authorisations", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

bankAuthorisation, err := client.BankAuthorisations.Get(ctx, "BAU123")

}
32 changes: 32 additions & 0 deletions code_sample_tests/bank_details_lookup_code_samples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBankDetailsLookupCreateCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("bank_details_lookups", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

bankDetailsLookupCreateParams := gocardless.BankDetailsLookupCreateParams{
AccountNumber: "55779911",
BranchCode: "200000",
CountryCode: "GB",
}

bankDetailsLookup, err := client.BankDetailsLookups.Create(ctx, bankDetailsLookupCreateParams)

}
156 changes: 156 additions & 0 deletions code_sample_tests/billing_request_code_samples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package code_sample_tests // Use a distinct package from the library itself to ensure code samples are tested in the same way as user code

// Code Sample Tests
// These tests verify that the documentation code samples are syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: These tests do NOT verify business logic - they only verify that
// the code samples compile and execute without syntax errors.

import (
"context"
"fmt"
"testing"

gocardless "github.com/gocardless/gocardless-pro-go/v6"
)

func TestBillingRequestCreateCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestCreateParams := gocardless.BillingRequestCreateParams{
PaymentRequest: &gocardless.BillingRequestCreateParamsPaymentRequest{
Amount: 1000,
Currency: "GBP",
Description: "First Payment",
},
MandateRequest: &gocardless.BillingRequestCreateParamsMandateRequest{
Scheme: "bacs",
},
}

billingRequest, err := client.BillingRequests.Create(ctx, billingRequestCreateParams)

}

func TestBillingRequestCollectCustomerDetailsCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestCollectCustomerDetailsParams := gocardless.BillingRequestCollectCustomerDetailsParams{
Customer: &gocardless.BillingRequestCollectCustomerDetailsParamsCustomer{
GivenName: "Alice",
FamilyName: "Smith",
Email: "alice@example.com",
},
CustomerBillingDetail: &gocardless.BillingRequestCollectCustomerDetailsParamsCustomerBillingDetail{
AddressLine1: "1 Somewhere Lane",
},
}

billingRequest, err := client.BillingRequests.CollectCustomerDetails(ctx, "BR123", billingRequestCollectCustomerDetailsParams)

}

func TestBillingRequestCollectBankAccountCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestCollectBankAccountParams := gocardless.BillingRequestCollectBankAccountParams{
BranchCode: "200000",
CountryCode: "GB",
AccountNumber: "55779911",
AccountHolderName: "Frank Osborne",
}

billingRequest, err := client.BillingRequests.CollectBankAccount(ctx, "BR123", billingRequestCollectBankAccountParams)

}

func TestBillingRequestConfirmPayerDetailsCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

BillingRequestConfirmPayerDetailsParams := gocardless.BillingRequestConfirmPayerDetailsParams{}
billingRequest, err := client.BillingRequests.ConfirmPayerDetails(ctx, "BR123", BillingRequestConfirmPayerDetailsParams)

}

func TestBillingRequestFulfilCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestFulfilParams := gocardless.BillingRequestFulfilParams{}
billingRequest, err := client.BillingRequests.Fulfil(ctx, "BR123", billingRequestFulfilParams)

}

func TestBillingRequestCancelCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestCancelParams := gocardless.BillingRequestCancelParams{}
billingRequest, err := client.BillingRequests.Cancel(ctx, "BR123", billingRequestCancelParams)

}

func TestBillingRequestListCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", true)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestListParams := gocardless.BillingRequestListParams{}
billingRequestListResult, err := client.BillingRequests.List(ctx, billingRequestListParams)
for _, billingRequest := range billingRequestListResult.BillingRequests {
fmt.Println(billingRequest.Id)
}

}

func TestBillingRequestGetCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequest, err := client.BillingRequests.Get(ctx, "BR123")

}

func TestBillingRequestNotifyCodeSample(t *testing.T) {
server := gocardless.RunCodeSampleServer("billing_requests", false)
defer server.Close()

ctx := context.TODO()
client, _ := gocardless.GetClient(t, server.URL)

billingRequestNotifyParams := gocardless.BillingRequestNotifyParams{
NotificationType: "email",
RedirectUri: "https://my-company.com",
}

billingRequest, err := client.BillingRequests.Notify(ctx, "BR123", billingRequestNotifyParams)

}
Loading
Loading