229 lines
6.6 KiB
Go
229 lines
6.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ChapaSecret string
|
|
ChapaBaseURL string
|
|
)
|
|
|
|
type InitPaymentRequest struct {
|
|
Amount Currency `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Email string `json:"email"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
TxRef string `json:"tx_ref"`
|
|
CallbackURL string `json:"callback_url"`
|
|
ReturnURL string `json:"return_url"`
|
|
}
|
|
|
|
type TransferRequest struct {
|
|
AccountNumber string `json:"account_number"`
|
|
BankCode string `json:"bank_code"`
|
|
Amount string `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Reference string `json:"reference"`
|
|
Reason string `json:"reason"`
|
|
RecipientName string `json:"recipient_name"`
|
|
}
|
|
|
|
type ChapaSupportedBank struct {
|
|
Id int64 `json:"id"`
|
|
Slug string `json:"slug"`
|
|
Swift string `json:"swift"`
|
|
Name string `json:"name"`
|
|
AcctLength int `json:"acct_length"`
|
|
AcctNumberRegex string `json:"acct_number_regex"`
|
|
ExampleValue string `json:"example_value"`
|
|
CountryId int `json:"country_id"`
|
|
IsMobilemoney *int `json:"is_mobilemoney"`
|
|
|
|
IsActive int `json:"is_active"`
|
|
IsRtgs *int `json:"is_rtgs"`
|
|
Active int `json:"active"`
|
|
Is24Hrs *int `json:"is_24hrs"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Currency string `json:"currency"`
|
|
}
|
|
|
|
type ChapaSupportedBanksResponse struct {
|
|
Message string `json:"message"`
|
|
Data []ChapaSupportedBank `json:"data"`
|
|
}
|
|
|
|
type InitPaymentData struct {
|
|
TxRef string `json:"tx_ref"`
|
|
CheckoutURL string `json:"checkout_url"`
|
|
}
|
|
|
|
type InitPaymentResponse struct {
|
|
Status string `json:"status"` // "success"
|
|
Message string `json:"message"` // e.g., "Payment initialized"
|
|
Data InitPaymentData `json:"data"`
|
|
}
|
|
|
|
type WebhookPayload map[string]interface{}
|
|
|
|
type TransactionData struct {
|
|
TxRef string `json:"tx_ref"`
|
|
Status string `json:"status"`
|
|
Amount string `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
CustomerEmail string `json:"email"`
|
|
}
|
|
|
|
type VerifyTransactionResponse struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Data TransactionData `json:"data"`
|
|
}
|
|
|
|
type TransferData struct {
|
|
Reference string `json:"reference"`
|
|
Status string `json:"status"`
|
|
Amount string `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
}
|
|
|
|
type CreateTransferResponse struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Data TransferData `json:"data"`
|
|
}
|
|
|
|
type TransferVerificationData struct {
|
|
Reference string `json:"reference"`
|
|
Status string `json:"status"`
|
|
BankCode string `json:"bank_code"`
|
|
AccountName string `json:"account_name"`
|
|
}
|
|
|
|
type VerifyTransferResponse struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Data TransferVerificationData `json:"data"`
|
|
}
|
|
|
|
type ChapaTransactionType struct {
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
type ChapaWebHookTransfer struct {
|
|
AccountName string `json:"account_name"`
|
|
AccountNumber string `json:"account_number"`
|
|
BankId string `json:"bank_id"`
|
|
BankName string `json:"bank_name"`
|
|
Currency string `json:"currency"`
|
|
Amount string `json:"amount"`
|
|
Type string `json:"type"`
|
|
Status string `json:"status"`
|
|
Reference string `json:"reference"`
|
|
TxRef string `json:"tx_ref"`
|
|
ChapaReference string `json:"chapa_reference"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type ChapaWebHookPayment struct {
|
|
Event string `json:"event"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Mobile interface{} `json:"mobile"`
|
|
Currency string `json:"currency"`
|
|
Amount string `json:"amount"`
|
|
Charge string `json:"charge"`
|
|
Status string `json:"status"`
|
|
Mode string `json:"mode"`
|
|
Reference string `json:"reference"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Type string `json:"type"`
|
|
TxRef string `json:"tx_ref"`
|
|
PaymentMethod string `json:"payment_method"`
|
|
Customization struct {
|
|
Title interface{} `json:"title"`
|
|
Description interface{} `json:"description"`
|
|
Logo interface{} `json:"logo"`
|
|
} `json:"customization"`
|
|
Meta string `json:"meta"`
|
|
}
|
|
|
|
type ChapaWithdrawRequest struct {
|
|
WalletID int64 `json:"wallet_id"` // add this
|
|
AccountName string `json:"account_name"`
|
|
AccountNumber string `json:"account_number"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
BeneficiaryName string `json:"beneficiary_name"`
|
|
BankCode string `json:"bank_code"`
|
|
BranchID int64 `json:"branch_id"`
|
|
}
|
|
|
|
type ChapaTransferPayload struct {
|
|
AccountName string
|
|
AccountNumber string
|
|
Amount string
|
|
Currency string
|
|
BeneficiaryName string
|
|
TxRef string
|
|
Reference string
|
|
BankCode string
|
|
}
|
|
|
|
type ChapaDepositRequest struct {
|
|
Amount Currency `json:"amount"`
|
|
PhoneNumber string `json:"phone_number"`
|
|
Currency string `json:"currency"`
|
|
BranchID int64 `json:"branch_id"`
|
|
}
|
|
|
|
func (r ChapaDepositRequest) Validate() error {
|
|
if r.Amount <= 0 {
|
|
return errors.New("amount must be greater than zero")
|
|
}
|
|
if r.Currency == "" {
|
|
return errors.New("currency is required")
|
|
}
|
|
if r.PhoneNumber == "" {
|
|
return errors.New("phone number is required")
|
|
}
|
|
// if r.BranchID == 0 {
|
|
// return errors.New("branch ID is required")
|
|
// }
|
|
|
|
return nil
|
|
}
|
|
|
|
type AcceptChapaPaymentRequest struct {
|
|
Amount string `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Email string `json:"email"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
PhoneNumber string `json:"phone_number"`
|
|
TxRef string `json:"tx_ref"`
|
|
CallbackUrl string `json:"callback_url"`
|
|
ReturnUrl string `json:"return_url"`
|
|
CustomizationTitle string `json:"customization[title]"`
|
|
CustomizationDescription string `json:"customization[description]"`
|
|
}
|
|
|
|
type ChapaPaymentUrlResponse struct {
|
|
PaymentURL string `json:"payment_url"`
|
|
}
|
|
|
|
type ChapaPaymentUrlResponseWrapper struct {
|
|
Data ChapaPaymentUrlResponse `json:"data"`
|
|
Response
|
|
}
|
|
|
|
type ChapaSupportedBanksResponseWrapper struct {
|
|
Data []ChapaSupportedBank `json:"data"`
|
|
Response
|
|
}
|