Multi Gateway Payment Package for Golang.
- zarinpal ✅
- payping ✅
- asanpardakht ✅
- behpardakht (mellat) ❌ (will be added soon)
- digipay ❌ (will be added soon)
- etebarino (Installment payment) ❌ (will be added soon)
- sepehr (saderat) ❌ (will be added soon)
- idpay ✅
- poolam ❌ (will be added soon)
- irankish ❌ (will be added soon)
- nextpay ❌ (will be added soon)
- parsian ❌ (will be added soon)
- pasargad ❌ (will be added soon)
- payir ❌ (will be added soon)
- paystar ❌ (will be added soon)
- sadad (melli) ❌ (will be added soon)
- saman ❌ (will be added soon)
- walleta (Installment payment) ❌ (will be added soon)
- yekpay ❌ (will be added soon)
- zibal ✅
- sepordeh ❌ (will be added soon)
- paypal ❌ (will be added soon)
- Help me to add the other gateways by creating
pull requests
go get -u github.com/mohammadv184/gopayment
In order to pay the invoice, we need the payment transactionId. We purchase the invoice to retrieve transaction id:
// Configure the Gateway Driver
gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
// Create new Payment.
payment := gopayment.NewPayment(gateway)
// Set Invoice Amount.
payment.Amount(amountInt)
// Set Invoice Description.
payment.Description("description")
// Purchase the invoice.
err = payment.Purchase()
if err != nil {
fmt.Println(err)
}
// Get Transaction ID
transactionID := payment.GetTransactionID()After purchasing the invoice, we can redirect the user to the bank payment page:
func pay() gin.HandlerFunc {
return func(c *gin.Context) {
// Configure the Gateway Driver
gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
// Create new Payment.
payment := gopayment.NewPayment(gateway)
// Set Invoice Amount.
payment.Amount(amountInt)
// Set Invoice Description.
payment.Description("description")
// Purchase the invoice.
err = payment.Purchase()
if err != nil {
fmt.Println(err)
}
// Get Transaction ID And Save it to the database.
transactionID := payment.GetTransactionID()
// Redirect the user to the bank payment page.
payUrl := payment.PayURL()
c.Redirect(http.StatusFound, payUrl)
}
}When user has completed the payment, the bank redirects them to your website, then you need to verify your payment to make sure that the payment is valid.:
// Configure the Gateway Driver
gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
refId := c.Query("refId")
VerifyRequest:=&payping.VerifyRequest{
Amount: "100",
RefID: refID,
}
if receipt, err := gateway.Verify(VerifyRequest); err == nil {
c.JSON(200, gin.H{
"status": "success",
"data": receipt.GetReferenceID(),
"date": receipt.GetDate().String(),
"card": receipt.GetDetail("cardNumber"),
"gateway": receipt.GetDriver(),
})
} else {
c.JSON(200, gin.H{
"message": "error " + err.Error(),
})
}When you make a payment, the invoice is automatically generated within the payment
In your code, use it like the below:
// Create new Payment.
payment := gopayment.NewPayment(gateway)
// Get the invoice.
invoice:=payment.GetInvoice()
// Set Invoice Amount.
invoice.SetAmount(1000)
// Set Invoice Description.
invoice.SetDescription("description")
// Set Invoice Deatils.
invoice.Detail("phone","0912345678")
invoice.Detail("email","example@example.com")Available methods:
SetUuid: set the invoice unique idGetUuid: retrieve the invoice current unique idDetail: attach some custom details into invoiceGetDetail: retrieve the invoice detailGetDetails: retrieve all custom detailsSetAmount: set the invoice amountGetAmount: retrieve invoice amountSetTransactionID: set invoice payment transaction idGetTransactionID: retrieve payment transaction idSetDescription: set invoice DescriptionGetDescription: retrieve payment Description
When you verify a payment, the receipt is automatically generated.
In your code, use it like the below:
// Verify the Payment.
receipt := gateway.verify(...)
// Get the Payment Reference ID.
refId := receipt.GetReferenceID()
// Get the payment date .
paymentDate:=receipt.GetDate()
// Get the payment driver name.
paymentDriver:=receipt.GetDriver()
// Get payment Deatils.
cardNum:=receipt.GetDetail("cardNumber")
cardHNum:=receipt.GetDetail("HashedCardNumber")
Available methods:
GetReferenceID: retrieve the payment reference idGetDriver: retrieve the payment driver nameDetail: attach some custom details into invoiceGetDate: retrieve payment dateGetDetail: retrieve the invoice detailGetDetails: retrieve all custom details
There is an example project using GoPayment you can find at GoPayment-Example Repo It contains a payment implementation.
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email mohammadv184@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
