-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #436 from Winter-Seminar-Series/payment
Added Zarinpal as payment service
- Loading branch information
Showing
16 changed files
with
396 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package idpay | ||
|
||
import ( | ||
"context" | ||
"wss-payment/pkg/payment" | ||
) | ||
|
||
type PaymentAdaptor struct { | ||
idpay IDPay | ||
} | ||
|
||
func NewPaymentAdaptor(apiKey string, sandboxed bool) PaymentAdaptor { | ||
return PaymentAdaptor{NewIDPay(apiKey, sandboxed)} | ||
} | ||
|
||
func (adaptor PaymentAdaptor) CreateTransaction(ctx context.Context, req payment.TransactionCreationRequest) (payment.TransactionCreationResult, error) { | ||
idpayRequest := TransactionCreationRequest{ | ||
OrderID: req.OrderID, | ||
Phone: req.UsersPhone, | ||
Mail: req.UsersMail, | ||
Description: req.Description, | ||
Callback: req.Callback, | ||
Amount: req.Amount, | ||
} | ||
idpayResult, err := adaptor.idpay.CreateTransaction(ctx, idpayRequest) | ||
if err != nil { | ||
return payment.TransactionCreationResult{}, err | ||
} | ||
return payment.TransactionCreationResult{ | ||
ServiceOrderID: idpayResult.ID, | ||
RedirectLink: idpayResult.Link, | ||
}, nil | ||
} | ||
|
||
func (adaptor PaymentAdaptor) VerifyTransaction(ctx context.Context, req payment.TransactionVerificationRequest) (payment.TransactionVerificationResult, error) { | ||
idpayRequest := TransactionVerificationRequest{ | ||
OrderID: req.OrderID, | ||
ID: req.ServiceOrderID, | ||
} | ||
idpayResult, err := adaptor.idpay.VerifyTransaction(ctx, idpayRequest) | ||
if err != nil { | ||
return payment.TransactionVerificationResult{}, err | ||
} | ||
return payment.TransactionVerificationResult{ | ||
TrackID: idpayResult.TrackID, | ||
PaymentOK: idpayResult.PaymentOK, | ||
}, nil | ||
} |
Oops, something went wrong.