The interactive walkthrough displays code examples alongside step-by-step explanations.
Follow the walkthrough to use the SDK in your Go code.
{/* Hidden markdown content for AI absorption and server rendering */}
/// Import required packages
Import the Payabli SDK to make it available in your code.
```go
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
```
/// Initialize the client
Create an authenticated client instance with your API key. This client has methods that call Payabli's API endpoints.
```go focus=13-16
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
func main() {
client := client.NewClient(option.WithApiKey("REPLACE_WITH_YOUR_API_KEY"))
}
```
/// Define the entrypoint
Define your entrypoint. Get this value from your Payabli account.
```go focus=17
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
func main() {
client := client.NewClient(option.WithApiKey("REPLACE_WITH_YOUR_API_KEY"))
entrypoint := "REPLACE_WITH_YOUR_ENTRYPOINT"
}
```
/// Build the payment request
Construct a request object that contains all the necessary fields to process a transaction. Include payment details, a payment method, and customer data.
```go focus=19-35
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
func main() {
client := client.NewClient(option.WithApiKey("REPLACE_WITH_YOUR_API_KEY"))
entrypoint := "REPLACE_WITH_YOUR_ENTRYPOINT"
request := &sdk.RequestPayment{
Body: &sdk.TransRequestBody{
EntryPoint: &entrypoint,
PaymentDetails: &sdk.PaymentDetail{
TotalAmount: 100.0,
},
PaymentMethod: &sdk.PaymentMethod{
PayMethodCredit: &sdk.PayMethodCredit{
Cardnumber: "4111111111111111",
Cardexp: "02/27",
},
},
CustomerData: &sdk.PayorDataRequest{
CustomerId: sdk.Int64(4440),
},
},
}
}
```
/// Execute the transaction
Call `MoneyIn.Getpaid()` to process the transaction. The client calls Payabli's `POST /MoneyIn/getpaid` endpoint.
```go focus=37-40
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
func main() {
client := client.NewClient(option.WithApiKey("REPLACE_WITH_YOUR_API_KEY"))
entrypoint := "REPLACE_WITH_YOUR_ENTRYPOINT"
request := &sdk.RequestPayment{
Body: &sdk.TransRequestBody{
EntryPoint: &entrypoint,
PaymentDetails: &sdk.PaymentDetail{
TotalAmount: 100.0,
},
PaymentMethod: &sdk.PaymentMethod{
PayMethodCredit: &sdk.PayMethodCredit{
Cardnumber: "4111111111111111",
Cardexp: "02/27",
},
},
CustomerData: &sdk.PayorDataRequest{
CustomerId: sdk.Int64(4440),
},
},
}
response, err := client.MoneyIn.Getpaid(context.Background(), request)
if err != nil {
log.Fatalf("Transaction failed: %v", err)
}
}
```
/// Show the result
Log the transaction response. Check the output to see if the transaction was successful.
```go focus=42
// main.go
package main
import (
"context"
"fmt"
"log"
sdk "github.com/payabli/sdk-go"
"github.com/payabli/sdk-go/client"
"github.com/payabli/sdk-go/option"
)
func main() {
client := client.NewClient(option.WithApiKey("REPLACE_WITH_YOUR_API_KEY"))
entrypoint := "REPLACE_WITH_YOUR_ENTRYPOINT"
request := &sdk.RequestPayment{
Body: &sdk.TransRequestBody{
EntryPoint: &entrypoint,
PaymentDetails: &sdk.PaymentDetail{
TotalAmount: 100.0,
},
PaymentMethod: &sdk.PaymentMethod{
PayMethodCredit: &sdk.PayMethodCredit{
Cardnumber: "4111111111111111",
Cardexp: "02/27",
},
},
CustomerData: &sdk.PayorDataRequest{
CustomerId: sdk.Int64(4440),
},
},
}
response, err := client.MoneyIn.Getpaid(context.Background(), request)
if err != nil {
log.Fatalf("Transaction failed: %v", err)
}
fmt.Printf("Transaction successful: %+v\n", response)
}
```