Skip to main content

Payment

The Payment component is a module within the EDK (Eagles Development Kit) that provides functionality for interacting with third-party payment providers. It enables your application to make API requests such as deducting funds, settling payments, and more.

Workflow

payment_workflow

Usage

To use the Payment component in your application, follow these steps:

  1. Import the Payment Client: Import the Payment client package into your application.

  2. Create a Payment Client: Create an instance of the Payment client, providing the necessary configuration and credentials. Payment Configuration can be found in Company component

  3. Make API Requests: Use the Payment client instance to make API requests to the payment provider

  4. Handle Responses: Handle the responses from the payment provider accordingly and handle any errors that may occur during API requests.

Example

    package main

import (
"context"
"log"

paymentcli "gitlab.ugaming.io/marketplace/edk/pkg/client/payment"
pb "gitlab.ugaming.io/marketplace/edk/pkg/company"
)

func main() {
inputUsername := ""

companies := []*pb.CompanyInfo{
{
FullName: "GamePortal",
ShortName: "gp",
Id: "9b3021b5-e2d7-4123-a2e8-b530a5e90693",
Key: "{KEY}",
Url: "{API_URL}",
},
}

payment, err := paymentcli.New(companies)
if err != nil {
log.Fatalf("could not new payment client: %v", err)
}

client, err := payment.GetProviderClient("9b3021b5-e2d7-4123-a2e8-b530a5e90693")
if err != nil {
log.Fatalf("could not get provider wallet client: %v", err)
return
}

r1, err := client.GetWallets(
context.Background(),
&paymentcli.GetWalletsRequest{
Usernames: []string{inputUsername},
})
if err != nil {
log.Printf("could not get wallet: %v", err)
}

log.Println(r1)

r2, err := client.Deduct(
context.Background(),
&paymentcli.DeductRequest{
Id: 1,
GameId: 1,
Transfers: []*paymentcli.Transfer{
{
Username: inputUsername,
Amount: 1000,
TransferLabel: 1,
},
},
})
if err != nil {
log.Printf("could not deduct: %v", err)
}

log.Println(r2)

r3, err := client.Settle(
context.Background(),
&paymentcli.SettleRequest{
Id: 1,
GameId: 1,
Transfers: []*paymentcli.Transfer{
{
Username: inputUsername,
Amount: 1000,
TransferLabel: 1,
},
},
})
if err != nil {
log.Printf("could not settle: %v", err)
}

log.Println(r3)
}

Error Handling

The Payment component may encounter errors during API requests. It's essential to handle and process these errors appropriately in your application. Refer to the documentation for the specific error handling mechanisms provided by the payment provider and the Payment client