duitku

package module
v0.0.0-...-ba54e6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

README

= Go client for duitku.com
Shulhan <ms@kilabit.info>
7 Nov 2022
:toc:
:sectanchors:

duitku is Go library and client for
https://duitku.com[duitku.com].

Supported HTTP APIs,

* Disbursement,

** https://docs.duitku.com/disbursement/en/#transfer-online[Transfer online^]
** https://docs.duitku.com/disbursement/en/#clearing-transaction-flow[Clearing^]
** https://docs.duitku.com/disbursement/en/#inquiry-list-bank[Inquiry list bank^]
** https://docs.duitku.com/disbursement/en/#inquiry-check-balance-request[Check balance^]

* Merchant,

** https://docs.duitku.com/api/en/#get-payment-method[Get payment method^]
** https://docs.duitku.com/api/en/#request-transaction[Inquiry^]
** https://docs.duitku.com/api/en/#check-transaction[Check transaction status^]

// SPDX-FileCopyrightText: 2022 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: GPL-3.0-or-later

Documentation

Overview

Package duitku provide library and HTTP client for duitku.com.

In the types, field that tagged with [REQ] is required and [OPT] is optional.

Index

Constants

View Source
const (
	CallbackCodeSuccess = `00`
	CallbackCodeFail    = `01`
)

List of callback status code.

View Source
const (
	PathListBank     = `/webapi/api/disbursement/listBank`
	PathCheckBalance = `/webapi/api/disbursement/checkBalance`

	// Paths for transfer online.
	PathInquiry        = `/webapi/api/disbursement/inquiry`
	PathInquirySandbox = `/webapi/api/disbursement/inquirysandbox` // Used for testing.

	// Endpoints to check transfer status.
	PathInquiryStatus        = `/webapi/api/disbursement/inquirystatus`
	PathInquiryStatusSandbox = `/webapi/api/disbursement/inquirystatus` // Used for testing.

	PathTransfer        = `/webapi/api/disbursement/transfer`
	PathTransferSandbox = `/webapi/api/disbursement/transfersandbox` // Used for testing.

	// Paths for Clearing.
	PathInquiryClearing        = `/webapi/api/disbursement/inquiryclearing`
	PathInquiryClearingSandbox = `/webapi/api/disbursement/inquiryclearingsandbox` // Used for testing.

	PathTransferClearing        = `/webapi/api/disbursement/transferclearing`
	PathTransferClearingSandbox = `/webapi/api/disbursement/transferclearingsandbox` // Used for testing.

	PathMerchantInquiry           = `/webapi/api/merchant/v2/inquiry`
	PathMerchantPaymentMethod     = `/webapi/api/merchant/paymentmethod/getpaymentmethod`
	PathMerchantTransactionStatus = `/webapi/api/merchant/transactionStatus`
)

List of known and implemented HTTP API paths.

View Source
const (
	ServerUrlLive    = `https://passport.duitku.com`
	ServerUrlSandbox = `https://sandbox.duitku.com`
)

List of duitku server URL for production and testing.

View Source
const (
	// ClearingTypeLLG LLG (Lalu Lintas Giro) is interbank transfer that
	// cover more than 130 bank in Indonesia.
	// The maximal amount transfer is IDR 500.000.000.
	// Transfer process follows the BI (Bank Indonesia) schedule, which is
	// 8.00-15.00 on business days.
	ClearingTypeLLG = `LLG`

	// ClearingTypeRTGS RTGS (Real Time Gross Settlement) is interbank transfer
	// that cover more than 130 bank in Indonesia.
	// The minimal amount transfer is IDR 100.000.000.
	// Transfer process follows the BI (Bank Indonesia) schedule, which is
	// 8.00-15.00 on business days.
	ClearingTypeRTGS = `RTGS`

	// ClearingTypeH2H (Bank Host to Host) Duitku Host to Host connection
	// to bank, to ensure direct connection and better reliability.
	// Currently only support 4 Major banks in Indonesia (BNI, BRI,
	// Mandiri, Permata).
	// Transfer schedule follows the schedule of each bank.
	ClearingTypeH2H = `H2H`

	// ClearingTypeBIFAST (Bank Indonesia Fast Payment) National retail
	// payments that can facilitate retail payments in real-time, safe,
	// efficient, more affordable service fees and available at any time
	// (24/7).
	ClearingTypeBIFAST = `BIFAST`
)
View Source
const (
	PaymentStatusSuccess = `00`
	PaymentStatusProcess = `01`
	PaymentStatusFailed  = `02`
)

List of valid Code in PaymentStatusResponse.

View Source
const (
	StatusCodeSuccess             = `00`   // Approved or completed successfully.
	StatusCodeError               = `EE`   // General Error.
	StatusCodeErrTimeout          = `TO`   // Response time out from ATM Bersama Network (Do not retry).
	StatusCodeErrLink             = `LD`   // Link problem between Duitku and ATM Bersama Network.
	StatusCodeErrNF               = `NF`   // Transaction has not recorded on Remittance gateway.
	StatusCodeErrAccountInvalid   = `76`   // Invalid destination account.
	StatusCodeErrCallbackWait     = `80`   // Waiting for callback.
	StatusCodeErrOther            = `-100` // Other error (do not retry).
	StatusCodeErrUserID           = `-120` // User not found.
	StatusCodeErrUserBlocked      = `-123` // User has been blocked.
	StatusCodeErrAmount           = `-141` // Amount transfer invalid.
	StatusCodeErrTxFinish         = `-142` // Transaction already Finished.
	StatusCodeErrBankH2H          = `-148` // Bank not support H2H.
	StatusCodeErrBankNotFound     = `-149` // Bank not found.
	StatusCodeErrCallbackNotFound = `-161` // Callback URL not found.
	StatusCodeErrSignature        = `-191` // Wrong signature.
	StatusCodeErrAccountBlocked   = `-192` // Account number is blacklisted.
	StatusCodeErrEmail            = `-213` // Email is not valid.
	StatusCodeErrTransferNotFound = `-420` // Transfer not Found.
	StatusCodeErrFundInsufficient = `-510` // Insufficient Fund.
	StatusCodeErrFundLimit        = `-920` // Limit Exceeded.
	StatusCodeErrIP               = `-930` // IP not whitelisted.
	StatusCodeErrVendorTimeout    = `-951` // Time Out Vendor.
	StatusCodeErrParam            = `-952` // Invalid Parameter.
	StatusCodeErrTimestampExpired = `-960` // Timestamp is expired (5 minutes).
)

List of known status codes.

View Source
const (
	ErrorCodeSuccess             = `00`
	ErrorCodeCardIssuer          = `01`
	ErrorCodeInvalidMerchant     = `03`
	ErrorCodeCaptureCard         = `04`
	ErrorCodeDonothonor          = `05`
	ErrorCodeInvalidTransaction  = `12`
	ErrorCodeInvalidAmount       = `13`
	ErrorCodeInvalidCardNumber   = `14`
	ErrorCodeInvalidIssuer       = `15`
	ErrorCodeInvalidResponse     = `20`
	ErrorCodeFormat              = `30`
	ErrorCodeUnsupportedBank     = `31`
	ErrorCodeExpiredCard         = `33`
	ErrorCodeRestrictedCard      = `36`
	ErrorCodePinTriesExceeded    = `38`
	ErrorCodeNoCreditAccount     = `39`
	ErrorCodeUnsupportedFunction = `40`
	ErrorCodeLostCard            = `41`
	ErrorCodeStolenCard          = `43`
	ErrorCodeInsufficientFund    = `51`
	ErrorCodeNoChequingAccount   = `52`
	ErrorCodeTimeout             = `68`
	ErrorCodeIssueNotOperative   = `91`
)

List of known error codes.

View Source
const (
	// PaymentMethodDatetimeLayout define the date and time format for
	// PaymentMethod.DateTime.
	//
	// TODO: replace with time.DateTime once the go version is 1.20.
	PaymentMethodDatetimeLayout = `2006-01-02 15:04:05`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountLink struct {
	// [REQ] Credential Code provide by Duitku.
	CredentialCode string `json:"credentialCode"`

	// [REQ] Mandatory for OVO payment.
	OVO AccountLinkOvo `json:"ovo"`

	// [REQ] Mandatory for Shopee payment.
	Shopee AccountLinkShopee `json:"shopee"`
}

AccountLink Parameter for payment methods that use OVO or Shopee account link.

type AccountLinkOvo

type AccountLinkOvo struct {
	PaymentDetails []OvoPaymentDetail `json:"paymentDetails"`
}

AccountLinkOvo account link information with OVO.

type AccountLinkShopee

type AccountLinkShopee struct {
	// [REQ] Voucher code.
	PromoIDs string `json:"promo_ids"`

	// [REQ] Used for shopee coin from linked ShopeePay account.
	// Set true when pay transaction would like to use coins (Only for
	// ShopeePay account link).
	UseCoin bool `json:"useCoin"`
}

AccountLinkShopee payment detail with Shopee.

type Address

type Address struct {
	FirstName   string `json:"firstName"`
	LastName    string `json:"lastName"`
	Address     string `json:"address"`
	City        string `json:"city"`
	PostalCode  string `json:"postalCode"`
	Phone       string `json:"phone"`
	CountryCode string `json:"countryCode"`
}

Address contains detailed address of customer.

type Balance

type Balance struct {
	Response

	// Current balance before settlement.
	Current *big.Rat `json:"balance"`

	// Effective Balance that can be used for disbursement.
	Effective *big.Rat `json:"effectiveBalance"`

	Email  string `json:"email"`
	UserID int64  `json:"userId"`
}

Balance contains the current user balances.

type Bank

type Bank struct {
	MaxTransfer *big.Rat `json:"maxAmountTransfer"`

	Code string `json:"bankCode"`
	Name string `json:"bankName"`
}

Bank contains bank information from response of ListBank.

type ClearingCallbackResponse

type ClearingCallbackResponse struct {
	AccountName   string `json:"accountName"`
	BankAccount   string `json:"bankAccount"`
	BankCode      string `json:"bankCode"`
	CustRefNumber string `json:"custRefNumber"`
	Email         string `json:"email"`

	ErrorMsg   string `json:"errorMessage"`
	StatusCode string `json:"statusCode"`
	StatusDesc string `json:"statusDesc"`

	Signature string `json:"signature"`

	Amount     int64 `json:"amountTransfer"`
	DisburseID int64 `json:"disburseId"`
	UserID     int64 `json:"userId"`
}

ClearingCallbackResponse contains fields that must be set in order to response from ClearingTransfer callback.

The signature created using the following formula:

SHA256(email + bankCode + bankAccount + accountName +
	custRefNumber + amountTransfer + disburseId + secretKey)

func NewClearingCallbackResponse

func NewClearingCallbackResponse(transferRes ClearingTransferResponse) (cbres *ClearingCallbackResponse)

NewClearingCallbackResponse create ClearingCallbackResponse from Clearing Transfer response.

The StatusCode is set to success initially.

func (*ClearingCallbackResponse) Sign

func (cbres *ClearingCallbackResponse) Sign(opts ClientOptions)

Sign set the Signature SHA256 and convert to hex.

type ClearingInquiry

type ClearingInquiry struct {
	// 9 digits customer reference number.
	CustRefNumber string `json:"custRefNumber"`

	// Type of clearing: LLG, RTGS, H2H, or BIFAST.
	Type string `json:"type"`

	RtolInquiry
}

ClearingInquiry contains request to initiate transfer from merchant to customer's bank account using Clearing type.

For Signature it use the following formula:

SHA256(email + timestamp + bankCode + type + bankAccount +
	amountTransfer + purpose + apiKey)

func (*ClearingInquiry) Sign

func (inq *ClearingInquiry) Sign(opts ClientOptions)

Sign the request, fill the UserID, Email, Timestamp, and generate the Signature.

type ClearingInquiryResponse

type ClearingInquiryResponse struct {
	Type string `json:"type"`

	RtolInquiryResponse
}

ClearingInquiryResponse contains response from calling Clearing Inquiry request.

type ClearingTransfer

type ClearingTransfer struct {
	Type string `json:"type"`

	RtolTransfer
}

ClearingTransfer contains request parameter for Clearing Transfer.

Formula to generate signature:

SHA256(email + timestamp + bankCode + type + bankAccount +
	accountName + custRefNumber + amountTransfer + purpose +
	disburseId + apiKey)

Ref: https://docs.duitku.com/disbursement/en/#clearing-transfer-request

func NewClearingTransfer

func NewClearingTransfer(inqReq *ClearingInquiry, inqRes *ClearingInquiryResponse) (trf *ClearingTransfer)

NewClearingTransfer create ClearingTransfer from Clearing Inquiry request and response.

The following fields are set from response: AccountName, CustRefNumber, DisburseID, and Type.

func (*ClearingTransfer) Sign

func (trf *ClearingTransfer) Sign(opts ClientOptions)

Sign the request, fill the UserID, Email, Timestamp, and generate the Signature.

type ClearingTransferResponse

type ClearingTransferResponse struct {
	Type string `json:"type"`

	RtolTransferResponse
}

ClearingTransferResponse contains response from Clearing Transfer.

type Client

type Client struct {
	*libhttp.Client
	// contains filtered or unexported fields
}

Client HTTP client for duitku disbursement and payment APIs.

func NewClient

func NewClient(opts ClientOptions) (cl *Client, err error)

NewClient create and initialize new Client.

func (*Client) CheckBalance

func (cl *Client) CheckBalance() (bal *Balance, err error)

CheckBalance get the current balances.

func (*Client) ClearingInquiry

func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryResponse, err error)

ClearingInquiry initiate the transfer for Clearing using LLG, RTGS, H2H, or BI-FAST.

func (*Client) ClearingTransfer

func (cl *Client) ClearingTransfer(req *ClearingTransfer) (res *ClearingTransferResponse, err error)

ClearingTransfer do the clearing transfer to the bank account.

Return without an error does not mean the transfer success, you need to check the response Code.

func (*Client) InquiryStatus

func (cl *Client) InquiryStatus(disburseID int64) (res *InquiryStatusResponse, err error)

InquiryStatus get the transfer status of ClearingTransfer or RtolTransfer.

func (*Client) ListBank

func (cl *Client) ListBank() (banks []Bank, err error)

ListBank fetch list of banks for disbursement. The returned list bank is sorted by code and name in ascending order.

func (*Client) MerchantInquiry

func (cl *Client) MerchantInquiry(req *MerchantInquiry) (resp *MerchantInquiryResponse, err error)

MerchantInquiry request payment to the Duitku system (via virtual account numbers, QRIS, e-wallet, and so on).

Ref: https://docs.duitku.com/api/en/#request-transaction

func (*Client) MerchantPaymentMethod

func (cl *Client) MerchantPaymentMethod(req *PaymentMethod) (resp *PaymentMethodResponse, err error)

MerchantPaymentMethod get active payment methods from the merchant (your) project.

Ref: https://docs.duitku.com/api/en/#get-payment-method

func (*Client) MerchantPaymentStatus

func (cl *Client) MerchantPaymentStatus(req *PaymentStatus) (resp *PaymentStatusResponse, err error)

MerchantPaymentStatus get the status of payment from customer.

func (*Client) Options

func (cl *Client) Options() (opts ClientOptions)

Options return the current client configuration.

func (*Client) RtolInquiry

func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err error)

RtolInquiry get the information of the name of the account owner of the transfer destination.

After getting this information, customers can determine whether the purpose of such a transfer is in accordance with the intended or not. If appropriate, the customer can proceed to the transfer process.

Ref: https://docs.duitku.com/disbursement/en/#transfer-online

func (*Client) RtolTransfer

func (cl *Client) RtolTransfer(req *RtolTransfer) (res *RtolTransferResponse, err error)

RtolTransfer do the actual transfer to customer's bank account.

Transfer will be limited from 25 to 50 Million per transaction depending on the beneficiary bank account.

Return without an error does not mean the transfer success, you need to check the response Code.

Ref: https://docs.duitku.com/disbursement/en/#online-transfer-transfer-request

type ClientOptions

type ClientOptions struct {
	ServerUrl string `ini:"duitku::server_url"`

	// DefaultMerchant default merchant to be used for payment.
	DefaultMerchant Merchant `ini:"default-merchant"`

	// PaymentMerchant specific merchant to be used based on payment
	// method.
	PaymentMerchant map[string]Merchant `ini:"merchant"`

	// DisburseApiKey API key for signing disbursement request.
	DisburseApiKey string `ini:"duitku::disburse_api_key"`

	// DisburseEmail The email registered for disbursement in Duitku.
	DisburseEmail string `ini:"duitku::disburse_email"`

	// DisburseUserID user ID for disbursement request.
	DisburseUserID int64 `ini:"duitku::disburse_user_id"`
	// contains filtered or unexported fields
}

ClientOptions configuration for HTTP client.

func LoadClientOptions

func LoadClientOptions(file string) (opts *ClientOptions, err error)

LoadClientOptions load ClientOptions from file. See the client.conf.example for an example for client configuration.

func (*ClientOptions) Merchant

func (opts *ClientOptions) Merchant(paymentMethod string) (merchant Merchant)

Merchant return the PaymentMerchant based on paymentMethod. If no key found, it will return DefaultMerchant.

type CustomerDetail

type CustomerDetail struct {
	FirstName       string  `json:"firstName"`
	LastName        string  `json:"lastName"`
	Email           string  `json:"email"`
	PhoneNumber     string  `json:"phoneNumber"`
	BillingAddress  Address `json:"billingAddress"`
	ShippingAddress Address `json:"shippingAddress"`
}

CustomerDetail detail of customer information for payment to merchant.

type InquiryStatus

type InquiryStatus struct {
	Request

	DisburseID int64 `json:"disburseId"`
}

InquiryStatus request for transfer status.

func (*InquiryStatus) Sign

func (inq *InquiryStatus) Sign(opts ClientOptions)

Sign the request, fill the UserID, Email, Timestamp, and generate the Signature.

type InquiryStatusResponse

type InquiryStatusResponse struct {
	Response

	// Destination Bank Code.
	BankCode string `json:"bankCode"`

	// Destination account number.
	BankAccount string `json:"bankAccount"`

	// Disbursement transfer amount.
	Amount *big.Rat `json:"amountTransfer"`

	// Bank Account owner.
	AccountName string `json:"accountName"`

	// 9 Digit Customer reference number that will be printed when the
	// transaction is successful.
	CustRefNumber string `json:"custRefNumber"`
}

InquiryStatusResponse define response valeus from InquiryStatus.

type ItemDetail

type ItemDetail struct {
	// [REQ] Name of the item.
	Name string `json:"name"`

	// [REQ] Quantity of the item bought.
	Quantity int64 `json:"quantity"`

	// [REQ] Price of the Item. Note: Don't add decimal
	Price int64 `json:"price"`
}

ItemDetail define the subset of product detail being payed during payment.

type Merchant

type Merchant struct {
	// The merchant code is the project code obtained from the Duitku
	// merchant page.
	// This code is useful as an identifier of your project in each
	// request using the /merchant/* APIs.
	Code string `ini:"::code"`

	// The API key for signing merchant request.
	ApiKey string `ini:"::api_key"`

	// The URL that will be used by Duitku to confirm payments made by
	// your customers.
	CallbackUrl string `ini:"::callback_url"`

	// The URL that Duitku will direct the customer after the transaction
	// is successful or canceled.
	ReturnUrl string `ini:"::return_url"`
}

Merchant the merchant configuration for payment.

You can get the values of Merchant from project you registered on the merchant portal.

type MerchantInquiry

type MerchantInquiry struct {
	// [REQ] MerchantCode is a project that use Duitku.
	//
	// You can get this code on every project you register on the
	// [merchant portal].
	// Default to ClientOptions.MerchantCode.
	//
	// [merchant portal]: https://passport.duitku.com/merchant/Project
	MerchantCode string `json:"merchantCode"`

	// [REQ] Transaction number from merchant.
	// Every request for a new transaction must use a new ID.
	MerchantOrderId string `json:"merchantOrderId"`

	// [REQ] PaymentMethod type of payment.
	//
	// Ref: https://docs.duitku.com/api/en/#payment-method
	PaymentMethod string `json:"paymentMethod"`

	// [REQ] Description about product/service on sale.
	//
	// You can fill in ProductDetails with a description of the product or
	// service that you provide.
	// You can also insert your store or brand name for more details.
	// Then in ItemDetails you can fill in product variants or product
	// model details, and other details about the products/services listed
	// in the transaction.
	ProductDetails string `json:"productDetails"`

	// [REQ] Customer's email.
	Email string `json:"email"`

	// [REQ] The name that would be shown at bank payment system.
	CustomerVaName string `json:"customerVaName"`

	// [REQ] A link that is used for redirect after exit payment page,
	// being paid or not.
	// Default to ClientOptions.MerchantReturnUrl.
	ReturnUrl string `json:"returnUrl"`

	// [REQ] A link for callback transaction.
	// Default to ClientOptions.MerchantCallbackUrl.
	CallbackUrl string `json:"callbackUrl"`

	// [REQ] Transaction security identification code.
	// Formula: MD5(merchantCode + merchantOrderId + paymentAmount + apiKey).
	Signature string `json:"signature"`

	// [OPT] Additional parameter to be used by merchant.
	// If its set, the value must be URL encoded.
	AdditionalParam string `json:"additionalParam,omitempty"`

	// [OPT] Customer's username.
	MerchantUserInfo string `json:"merchantUserInfo,omitempty"`

	// [OPT] Customer's phone number.
	PhoneNumber string `json:"phoneNumber,omitempty"`

	// [OPT] Customer's details.
	// [REQ] If PaymentMethod is Credit (DN/AT).
	CustomerDetail *CustomerDetail `json:"customerDetail,omitempty"`

	// [OPT] Details for payment method.
	AccountLink *AccountLink `json:"accountLink,omitempty"`

	// [OPT] Detail of product being payed.
	// [REQ] If PaymentMethod is Credit (DN/AT).
	//
	// The total of all price in ItemDetails must exactly match the
	// PaymentAmount.
	ItemDetails []ItemDetail `json:"itemDetails,omitempty"`

	// [REQ] Amount of transaction.
	//
	// Make sure the PaymentAmount is equal to the total Price in the
	// ItemDetails.
	PaymentAmount int64 `json:"paymentAmount"`

	// [OPT] Transaction expiry period in minutes.
	// If its empty, it will set to [default] based on PaymentMethod.
	//
	// [default]: https://docs.duitku.com/api/en/#expiry-period
	ExpiryPeriod int `json:"expiryPeriod,omitempty"`
}

MerchantInquiry define request data for payment using merchant.

type MerchantInquiryResponse

type MerchantInquiryResponse struct {
	// Indicates which project used in this transaction.
	MerchantCode string `json:"merchantCode"`

	// Reference number from Duitku (need to be save on your system).
	Reference string `json:"reference"`

	// Payment link for direction to Duitku payment page.
	PaymentUrl string `json:"paymentUrl"`

	// Payment number or virtual account.
	VANumber string `json:"vaNumber"`

	// QR string is used if you use QRIS payment (you need to generate QR
	// code from this string).
	QRString string `json:"qrString"`

	// Payment amount.
	Amount string `json:"amount"`

	// Status code transaction.
	//   - 00 - Success
	//   - 01 - Process
	//   - 02 - Failed/Expired
	Code string `json:"statusCode"`

	// Description that explain the status Code.
	Message string `json:"statusMessage"`

	// Response body when http request failed
	ErrorMessage string `json:"Message,omitempty"`
}

MerchantInquiryResponse contains response from MerchantInquiry.

type OvoPaymentDetail

type OvoPaymentDetail struct {
	// [REQ] Type of your payment.
	PaymentType string `json:"paymentType"`

	// [REQ] Transaction payment amount.
	Amount int64 `json:"amount"`
}

OvoPaymentDetail payment detail for account link OVO.

type PaymentFee

type PaymentFee struct {
	// Payment method code.
	PaymentMethod string `json:"paymentMethod"`

	// Payment method name.
	PaymentName string `json:"paymentName"`

	// Payment method image url.
	PaymentImage string `json:"paymentImage"`

	// Payment Fee.
	TotalFee string `json:"totalFee"`
}

PaymentFee contains fee for payment method.

If the settings in the merchant portal fees are charged to the merchant, the TotalFee will appear 0. The TotalFee will appear if it is charged to the customer.

type PaymentMethod

type PaymentMethod struct {
	// [REQ] Merchant code from Duitku.
	// Set by calling sign from ClientOptions.
	MerchantCode string `json:"merchantcode"`

	// [REQ] Format: yyyy-MM-dd HH:mm:ss
	// If empty, it will be set during sign using current date time.
	DateTime string `json:"datetime"`

	// [REQ] Formula: Sha256(merchantcode + paymentAmount + datetime +
	// apiKey).
	// The value of hash is stored as lowercase hexadecimal.
	Signature string `json:"signature"`

	// [REQ] Transaction amount. No decimal code (.) and no decimal digit.
	Amount int64 `json:"amount"`
}

PaymentMethod contains request for client MerchantPaymentMethod.

func (*PaymentMethod) SetDateTime

func (req *PaymentMethod) SetDateTime(t time.Time)

SetDateTime set the field DateTime using t.

func (*PaymentMethod) Sign

func (req *PaymentMethod) Sign(opts ClientOptions)

Sign the request. Set the MerchantCode and DateTime if its empty, and then generate the Signature.

type PaymentMethodResponse

type PaymentMethodResponse struct {
	Response

	PaymentFee []PaymentFee `json:"paymentFee"`
}

PaymentMethodResponse contains list of payments enabled by merchant.

type PaymentStatus

type PaymentStatus struct {
	MerchantCode string `form:"merchantCode"`
	OrderID      string `form:"merchantOrderId"`

	// Transaction identification code.
	// Formula: md5(merchantCode + merchantOrderId + apiKey).
	Signature string `form:"signature"`
}

PaymentStatus define the request to get the latest order ID payment status based on its merchant.

type PaymentStatusResponse

type PaymentStatusResponse struct {
	OrderID   string `json:"merchantOrderId"`
	Reference string `json:"reference"`
	Amount    string `json:"amount"`

	// Status code transaction.
	//   - 00 - Success
	//   - 01 - Process
	//   - 02 - Failed/Expired
	Code string `json:"statusCode"`

	// Description that explain the status Code.
	Message string `json:"statusMessage"`
}

PaymentStatusResponse contains response from checking merchant payment status.

type Request

type Request struct {
	// Merchant email, filled from ClientOptions.Email.
	Email string `json:"email"`

	// Hash of some fields in the request along with its ApiKey.
	Signature string `json:"signature"`

	// Merchant ID, filled from ClientOptions.UserID.
	UserID int64 `json:"userId"`

	// Unix Timestamp in milliseconds.
	Timestamp int64 `json:"timestamp"`
}

Request define common HTTP request fields.

func CreateDisburseRequest

func CreateDisburseRequest(opts ClientOptions) (req Request)

CreateDisburseRequest create request for disbursement using ClientOptions opts.

type Response

type Response struct {
	Code string `json:"responseCode"`
	Desc string `json:"responseDesc"`
}

Response contains commons fields for each HTTP response.

func (*Response) IsSuccess

func (res *Response) IsSuccess() bool

IsSuccess return true if the response code equal to 00.

type RtolInquiry

type RtolInquiry struct {
	// Destination Bank Code.
	BankCode string `json:"bankCode"`

	// Destination account number.
	BankAccount string `json:"bankAccount"`

	// Description of transfer purpose.
	Purpose string `json:"purpose"`

	// Customer name provided by merchant.
	SenderName string `json:"senderName"`

	Request

	// Customer ID provided by merchant.
	SenderID int64 `json:"senderID"`

	// Disbursement transfer amount.
	Amount int64 `json:"amountTransfer"`
}

RtolInquiry contains request to initiate transfer from merchant to customer's bank account using Online Transfer.

The signature formula is:

SHA256(email + timestamp + bankCode + bankAccount + amountTransfer +
	purpose + apiKey)

func (*RtolInquiry) Sign

func (inq *RtolInquiry) Sign(opts ClientOptions)

Sign the request, fill the UserID, Email, Timestamp, and generate the Signature.

type RtolInquiryResponse

type RtolInquiryResponse struct {
	Response

	// Email sent when inquiry process.
	Email string `json:"email"`

	// Destination Bank Code.
	BankCode string `json:"bankCode"`

	// Destination account number.
	BankAccount string `json:"bankAccount"`

	// Disbursement transfer amount.
	Amount *big.Rat `json:"amountTransfer"`

	// Bank Account owner.
	AccountName string `json:"accountName"`

	// 9 Digit Customer reference number that will be printed when the
	// transaction is successful.
	CustRefNumber string `json:"custRefNumber"`

	// Disbursement ID from duitku. Please save it for checking purpose.
	DisburseID int64 `json:"disburseId"`
}

RtolInquiryResponse contains response from inquiry for Online Transfer.

type RtolTransfer

type RtolTransfer struct {
	// Bank Account owner, obtained after getting a response from the
	// inquiry process.
	AccountName string `json:"accountName"`

	// Destination Bank Code sent when inquiry process.
	BankCode string `json:"bankCode"`

	// Destination account number sent when inquiry procces.
	BankAccount string `json:"bankAccount"`

	// Customer reference number, obtained after getting a response from
	// the inquiry process.
	CustRefNumber string `json:"custRefNumber"`

	// Description of transfer purpose.
	Purpose string `json:"purpose"`

	Request

	// Disbursement transfer amount.
	Amount int64 `json:"amountTransfer"`

	// Disbursement Id provided by Duitku, obtained after getting a
	// response from the inquiry process.
	DisburseID int64 `json:"disburseId"`
}

RtolTransfer containts request to transfer amount from merchant to customer's bank account, using the previous data obtained from the inquiry process.

The formula to generate Signature is SHA256(email + timestamp + bankCode + bankAccount + accountName + custRefNumber + amountTransfer + purpose + disburseId + secretKey).

Ref: https://docs.duitku.com/disbursement/en/#online-transfer-transfer-request

func NewRtolTransfer

func NewRtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryResponse) (req *RtolTransfer)

NewRtolTransfer create new RtolTransfer request from request and response of RtolInquiry.

func (*RtolTransfer) Sign

func (req *RtolTransfer) Sign(opts ClientOptions)

Sign the request, fill the UserID, Email, Timestamp, and generate the Signature.

type RtolTransferResponse

type RtolTransferResponse struct {
	Purpose string `json:"purpose"`

	RtolInquiryResponse

	UserID int64 `json:"userId"`
}

RtolTransferResponse contains response from online transfer.

NOTE: the actual response from server does not return DisburseID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL