midtrans

package module
v0.0.0-...-16326c5 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 13 Imported by: 21

README


⚠⚠ IMPORTANT ANNOUNCEMENT ⚠⚠

Please use the updated and revamped: Midtrans Go. For better and more intuitive usage.

Click Here to Learn More

This library was created in the early days, then we realize some of the designs and patterns used in this library is not the best and easiest to maintain. We learn from the mistakes, and decide it will be better to revamp as brand new Midtrans Go library. This decision is to avoid forcing breaking changes to this library, allow old users to migrate as they see fit, and allows better flexibility on the revamped design. Thank you for your support, contributions, and understanding. 🙂

This repo still be here for archive and backward-compatibility purpose for those who still use it. But it's always recommended to use the newer version Midtrans Go.

🔈 END OF ANNOUNCEMENT 🔈


Midtrans Library for Go(lang)

Go Report Card Apache 2.0 license Build Status

Midtrans ❤ Go !

Go is a very modern, terse, and combine aspect of dynamic and static typing that in a way very well suited for web development, among other things. Its small memory footprint is also an advantage of itself. Now, Midtrans is available to be used in Go, too.

Usage blueprint

  1. There is a type named Client (midtrans.Client) that should be instantiated through NewClient which hold any possible setting to the library.
  2. There is a gateway classes which you will be using depending on whether you used Core, SNAP, SNAP-Redirect. The gateway type need a Client instance.
  3. Any activity (charge, approve, etc) is done in the gateway level.

Example

We have attached usage examples in this repository in folder example/simplepay. Please proceed there for more detail on how to run the example.

Core Gateway
    midclient := midtrans.NewClient()
    midclient.ServerKey = "YOUR-VT-SERVER-KEY"
    midclient.ClientKey = "YOUR-VT-CLIENT-KEY"
    midclient.APIEnvType = midtrans.Sandbox

    coreGateway := midtrans.CoreGateway{
        Client: midclient,
    }

    chargeReq := &midtrans.ChargeReq{
        PaymentType: midtrans.SourceCreditCard,
        TransactionDetails: midtrans.TransactionDetails{
            OrderID: "12345",
            GrossAmt: 200000,
        },
        CreditCard: &midtrans.CreditCardDetail{
            TokenID: "YOUR-CC-TOKEN",
        },
        Items: &[]midtrans.ItemDetail{
            midtrans.ItemDetail{
                ID: "ITEM1",
                Price: 200000,
                Qty: 1,
                Name: "Someitem",
            },
        },
    }

    resp, _ := coreGateway.Charge(chargeReq)
How Core API does charge with map type

please refer to file main.go in folder example/simplepay

func ChargeWithMap(w http.ResponseWriter, r *http.Request) {
	var reqPayload = &midtrans.ChargeReqWithMap{}
	err := json.NewDecoder(r.Body).Decode(reqPayload)
	if err != nil {
		// do something
		return
	}
	
	chargeResp, _ := coreGateway.ChargeWithMap(reqPayload)
	result, err := json.Marshal(chargeResp)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(result)
}
Snap Gateway

Snap is Midtrans existing tool to help merchant charge customers using a mobile-friendly, in-page, no-redirect checkout facilities. Using snap is completely simple.

Quick transaction with minimum Snap parameters:

var snapGateway midtrans.SnapGateway
snapGateway = midtrans.SnapGateway{
  Client: midclient,
}

snapResp, err := snapGateway.GetTokenQuick(generateOrderId(), 200000)
var snapToken string
if err != nil {
  snapToken = snapResp.Token
}

On the client side:

var token = $("#snap-token").val();
snap.pay(token, {
    onSuccess: function(res) { alert("Payment accepted!"); },
    onPending: function(res) { alert("Payment pending", res); },
    onError: function(res) { alert("Error", res); }
});

You may want to override those onSuccess, onPending and onError functions to reflect the behaviour that you wished when the charging result in their respective state.

Alternativelly, more complete Snap parameter:


    midclient := midtrans.NewClient()
    midclient.ServerKey = "YOUR-VT-SERVER-KEY"
    midclient.ClientKey = "YOUR-VT-CLIENT-KEY"
    midclient.APIEnvType = midtrans.Sandbox

    var snapGateway midtrans.SnapGateway
    snapGateway = midtrans.SnapGateway{
        Client: midclient,
    }

    custAddress := &midtrans.CustAddress{
        FName: "John",
        LName: "Doe",
        Phone: "081234567890",
        Address: "Baker Street 97th",
        City: "Jakarta",
        Postcode: "16000",
        CountryCode: "IDN",
    }

    snapReq := &midtrans.SnapReq{
        TransactionDetails: midtrans.TransactionDetails{
            OrderID: "order-id-go-"+timestamp,
            GrossAmt: 200000,
        },
        CustomerDetail: &midtrans.CustDetail{
            FName: "John",
            LName: "Doe",
            Email: "john@doe.com",
            Phone: "081234567890",
            BillAddr: custAddress,
            ShipAddr: custAddress,
        },
        Items: &[]midtrans.ItemDetail{
            midtrans.ItemDetail{
                ID: "ITEM1",
                Price: 200000,
                Qty: 1,
                Name: "Someitem",
            },
        },
    }

    log.Println("GetToken:")
    snapTokenResp, err := snapGateway.GetToken(snapReq)
Handle HTTP Notification

Create separated web endpoint (notification url) to receive HTTP POST notification callback/webhook. HTTP notification will be sent whenever transaction status is changed. Example also available in main.go in folder example/simplepay

func notification(w http.ResponseWriter, r *http.Request) {
	var reqPayload = &midtrans.ChargeReqWithMap{}
	err := json.NewDecoder(r.Body).Decode(reqPayload)
	if err != nil {
		// do something
		return
	}

	encode, _ := json.Marshal(reqPayload)
	resArray := make(map[string]string)
	err = json.Unmarshal(encode, &resArray)

	chargeResp, _ := coreGateway.StatusWithMap(resArray["order_id"])
	result, err := json.Marshal(chargeResp)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(result)
}
Iris Gateway

Iris is Midtrans cash management solution that allows you to disburse payments to any bank accounts in Indonesia securely and easily. Iris connects to the banks’ hosts to enable seamless transfer using integrated APIs.

Note: ServerKey used for irisGateway's Client is API Key found in Iris Dashboard. The API Key is different with Midtrans' payment gateway account's key.

var irisGateway midtrans.IrisGateway
irisGateway = midtrans.IrisGateway{
  Client: midclient,
}

res, err := irisGateway.GetListBeneficiaryBank()
if err != nil {
    fmt.Println("err ", err)
    return
}
fmt.Printf("result %v \n ", res.BeneficiaryBanks)

License

See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

AllPaymentSource : Get All available PaymentType

Functions

This section is empty.

Types

type Action

type Action struct {
	Name   string `json:"name"`
	Method string `json:"method"`
	URL    string `json:"url"`
}

Action represents response action

type BCABankTransferDetail

type BCABankTransferDetail struct {
	Bank     Bank                          `json:"bank"`
	VaNumber string                        `json:"va_number"`
	FreeText BCABankTransferDetailFreeText `json:"free_text"`
}

BCABankTransferDetail : Represent BCA bank_transfer detail

type BCABankTransferDetailFreeText

type BCABankTransferDetailFreeText struct {
	Inquiry []BCABankTransferLangDetail `json:"inquiry,omitempty"`
	Payment []BCABankTransferLangDetail `json:"payment,omitempty"`
}

BCABankTransferDetailFreeText : Represent BCA bank_transfer detail free_text

type BCABankTransferLangDetail

type BCABankTransferLangDetail struct {
	LangID string `json:"id,omitempty"`
	LangEN string `json:"en,omitempty"`
}

BCABankTransferLangDetail : Represent BCA bank_transfer lang detail

type BCAKlikBCADetail

type BCAKlikBCADetail struct {
	Desc   string `json:"description"`
	UserID string `json:"user_id"`
}

BCAKlikBCADetail : Represent BCA KlikBCA detail

type BCAKlikPayDetail

type BCAKlikPayDetail struct {
	// 1 = normal, 2 = installment, 3 = normal + installment
	Type    string `json:"type"`
	Desc    string `json:"description"`
	MiscFee int64  `json:"misc_fee,omitempty"`
}

BCAKlikPayDetail : Represent Internet Banking for BCA KlikPay

type Bank

type Bank string

Bank value

const (
	//BankBni : bni
	BankBni Bank = "bni"

	//BankMandiri : mandiri
	BankMandiri Bank = "mandiri"

	//BankCimb : cimb
	BankCimb Bank = "cimb"

	//BankBca : bca
	BankBca Bank = "bca"

	//BankBri : bri
	BankBri Bank = "bri"

	//BankMaybank : maybank
	BankMaybank Bank = "maybank"

	//BankPermata : permata
	BankPermata Bank = "permata"
)

type BankTransferDetail

type BankTransferDetail struct {
	Bank     Bank                           `json:"bank,omitempty"`
	VaNumber string                         `json:"va_number,omitempty"`
	FreeText *BCABankTransferDetailFreeText `json:"free_text,omitempty"`
	*MandiriBillBankTransferDetail
}

BankTransferDetail : Represent bank_transfer detail

type CIMBClicksDetail

type CIMBClicksDetail struct {
	Desc string `json:"description"`
}

CIMBClicksDetail : Represent CIMB Clicks detail

type Callbacks

type Callbacks struct {
	Finish string `json:"finish"`
}

type CaptureReq

type CaptureReq struct {
	TransactionID string  `json:"transaction_id"`
	GrossAmt      float64 `json:"gross_amount"`
}

CaptureReq : Represent Capture request payload

type ChargeReq

type ChargeReq struct {
	PaymentType        PaymentType        `json:"payment_type"`
	TransactionDetails TransactionDetails `json:"transaction_details"`

	CreditCard                    *CreditCardDetail              `json:"credit_card,omitempty"`
	BankTransfer                  *BankTransferDetail            `json:"bank_transfer,omitempty"`
	MandiriBillBankTransferDetail *MandiriBillBankTransferDetail `json:"echannel,omitempty"`
	BCAKlikPay                    *BCAKlikPayDetail              `json:"bca_klikpay,omitempty"`
	BCAKlikBCA                    *BCAKlikBCADetail              `json:"bca_klikbca,omitempty"`
	MandiriClickPay               *MandiriClickPayDetail         `json:"mandiri_clickpay,omitempty"`
	MandiriEcash                  *MandiriEcashDetail            `json:"mandiri_ecash,omitempty"`
	CIMBClicks                    *CIMBClicksDetail              `json:"cimb_clicks,omitempty"`
	TelkomselCash                 *TelkomselCashDetail           `json:"telkomsel_cash,omitempty"`
	IndosatDompetku               *IndosatDompetkuDetail         `json:"indosat_dompetku,omitempty"`
	CustomerDetail                *CustDetail                    `json:"customer_details,omitempty"`
	ConvStore                     *ConvStoreDetail               `json:"cstore,omitempty"`
	Gopay                         *GopayDetail                   `json:"gopay,omitempty"`
	ShopeePay                     *ShopeePayDetail               `json:"shopeepay,omitempty"`

	Items        *[]ItemDetail `json:"item_details,omitempty"`
	CustField1   string        `json:"custom_field1,omitempty"`
	CustField2   string        `json:"custom_field2,omitempty"`
	CustField3   string        `json:"custom_field3,omitempty"`
	CustomExpiry *CustomExpiry `json:"custom_expiry,omitempty"`
}

ChargeReq : Represent Charge request payload

type ChargeReqWithMap

type ChargeReqWithMap map[string]interface{}

ChargeReqWithMap : Represent Charge request with map payload

type Client

type Client struct {
	APIEnvType EnvironmentType
	ClientKey  string
	ServerKey  string

	LogLevel int
	Logger   *log.Logger
}

Client struct

func NewClient

func NewClient() Client

NewClient : this function will always be called when the library is in use

func (*Client) Call

func (c *Client) Call(method, path string, body io.Reader, v interface{}) error

Call the Midtrans API at specific `path` using the specified HTTP `method`. The result will be given to `v` if there is no error. If any error occurred, the return of this function is the error itself, otherwise nil.

func (*Client) ExecuteRequest

func (c *Client) ExecuteRequest(req *http.Request, v interface{}) error

ExecuteRequest : execute request

func (*Client) NewRequest

func (c *Client) NewRequest(method string, fullPath string, body io.Reader) (*http.Request, error)

NewRequest : send new request

type ConvStoreDetail

type ConvStoreDetail struct {
	Store   string `json:"store"`
	Message string `json:"message"`
}

ConvStoreDetail : Represent cstore detail

type CoreGateway

type CoreGateway struct {
	Client Client
}

CoreGateway struct

func (*CoreGateway) Approve

func (gateway *CoreGateway) Approve(orderID string) (Response, error)

Approve : Approve order using order ID

func (*CoreGateway) Call

func (gateway *CoreGateway) Call(method, path string, body io.Reader, v interface{}) error

Call : base method to call Core API

func (*CoreGateway) Cancel

func (gateway *CoreGateway) Cancel(orderID string) (Response, error)

Cancel : Cancel order using order ID

func (*CoreGateway) CaptureCard

func (gateway *CoreGateway) CaptureCard(req *CaptureReq) (Response, error)

CaptureCard : Capture an authorized transaction for card payment

func (*CoreGateway) Charge

func (gateway *CoreGateway) Charge(req *ChargeReq) (Response, error)

Charge : Perform transaction using ChargeReq

func (*CoreGateway) ChargeWithMap

func (gateway *CoreGateway) ChargeWithMap(req *ChargeReqWithMap) (ResponseWithMap, error)

ChargeWithMap : Perform transaction using ChargeReqWithMap

func (*CoreGateway) Deny

func (gateway *CoreGateway) Deny(orderID string) (Response, error)

Deny : Deny a transaction using order ID which gets challenge status from Fraud Detection System

func (*CoreGateway) DirectRefund

func (gateway *CoreGateway) DirectRefund(orderID string, req *RefundReq) (Response, error)

DirectRefund : refund order using order ID

func (*CoreGateway) Expire

func (gateway *CoreGateway) Expire(orderID string) (Response, error)

Expire : change order status to expired using order ID

func (*CoreGateway) PreauthCard

func (gateway *CoreGateway) PreauthCard(req *ChargeReq) (Response, error)

PreauthCard : Perform authorized transactions using ChargeReq

func (*CoreGateway) Refund

func (gateway *CoreGateway) Refund(orderID string, req *RefundReq) (Response, error)

Refund : refund order using order ID

func (*CoreGateway) Status

func (gateway *CoreGateway) Status(orderID string) (Response, error)

Status : get order status using order ID

func (*CoreGateway) StatusWithMap

func (gateway *CoreGateway) StatusWithMap(orderID string) (ResponseWithMap, error)

StatusWithMap : get order status using order ID

func (*CoreGateway) Subscribe

func (gateway *CoreGateway) Subscribe(req *SubscribeReq) (SubscribeResponse, error)

Subscribe : Perform transaction using subscriptions

func (*CoreGateway) SubscribeDetail

func (gateway *CoreGateway) SubscribeDetail(subscriptionID string) (SubscribeResponse, error)

SubscribeDetail : Perform get subscription details

func (*CoreGateway) SubscribeDisable

func (gateway *CoreGateway) SubscribeDisable(subscriptionID string) (SubscribeResponse, error)

SubscribeDisable : Perform disable a subscription

func (*CoreGateway) SubscribeEnable

func (gateway *CoreGateway) SubscribeEnable(subscriptionID string) (SubscribeResponse, error)

SubscribeEnable : Perform enable a subscription

func (*CoreGateway) SubscribeUpdate

func (gateway *CoreGateway) SubscribeUpdate(subscriptionID string, req *SubscribeReq) (SubscribeResponse, error)

SubscribeUpdate : Perform update a subscription

type CreditCardDetail

type CreditCardDetail struct {
	Secure          bool               `json:"secure,omitempty"`
	TokenID         string             `json:"token_id"`
	Bank            string             `json:"bank,omitempty"`
	Bins            []string           `json:"bins,omitempty"`
	WhitelistBins   []string           `json:"whitelist_bins,omitempty"`
	Installment     *InstallmentDetail `json:"installment,omitempty"`
	InstallmentTerm int8               `json:"installment_term,omitempty"`
	Type            string             `json:"type,omitempty"`
	// indicate if generated token should be saved for next charge
	SaveCard             bool   `json:"save_card,omitempty"`
	CardToken            string `json:"card_token,omitempty"`
	SaveTokenID          bool   `json:"save_token_id,omitempty"`
	SavedTokenIDExpireAt string `json:"saved_token_id_expired_at,omitempty"`
	Authentication       bool   `json:"authentication,omitempty"`
}

CreditCardDetail : Represent credit card detail

type CustAddress

type CustAddress struct {
	FName       string `json:"first_name"`
	LName       string `json:"last_name"`
	Phone       string `json:"phone"`
	Address     string `json:"address"`
	City        string `json:"city"`
	Postcode    string `json:"postal_code"`
	CountryCode string `json:"country_code"`
}

CustAddress : Represent the customer address

type CustDetail

type CustDetail struct {
	// first name
	FName string `json:"first_name,omitempty"`

	// last name
	LName string `json:"last_name,omitempty"`

	Email    string       `json:"email,omitempty"`
	Phone    string       `json:"phone,omitempty"`
	BillAddr *CustAddress `json:"billing_address,omitempty"`
	ShipAddr *CustAddress `json:"customer_address,omitempty"`
}

CustDetail : Represent the customer detail

type CustomExpiry

type CustomExpiry struct {
	OrderTime      string `json:"order_time,omitempty"`
	ExpiryDuration int    `json:"expiry_duration,omitempty"`
	Unit           string `json:"unit,omitempty"`
}

CustomExpiry : Represent Core API custom_expiry

type EnvironmentType

type EnvironmentType int8

EnvironmentType value

const (

	// Sandbox : represent sandbox environment
	Sandbox EnvironmentType

	// Production : represent production environment
	Production
)

func (EnvironmentType) IrisURL

func (e EnvironmentType) IrisURL() string

IrisURL : Get environment API URL

func (EnvironmentType) SnapURL

func (e EnvironmentType) SnapURL() string

SnapURL : Get environment API URL

func (EnvironmentType) String

func (e EnvironmentType) String() string

implement stringer

type ExpiryDetail

type ExpiryDetail struct {
	StartTime string `json:"start_time,omitempty"`
	Unit      string `json:"unit"`
	Duration  int64  `json:"duration"`
}

ExpiryDetail : Represent SNAP expiry details

type GopayDetail

type GopayDetail struct {
	EnableCallback bool   `json:"enable_callback"`
	CallbackUrl    string `json:"callback_url"`
}

GopayDetail : Represent gopay detail

type IndosatDompetkuDetail

type IndosatDompetkuDetail struct {
	MSISDN string `json:"msisdn"`
}

IndosatDompetkuDetail : Represent Indosat Dompetku detail

type InstallmentDetail

type InstallmentDetail struct {
	Required bool                    `json:"required"`
	Terms    *InstallmentTermsDetail `json:"terms"`
}

InstallmentDetail : Represent installment detail

type InstallmentTermsDetail

type InstallmentTermsDetail struct {
	Bni     []int8 `json:"bni,omitempty"`
	Mandiri []int8 `json:"mandiri,omitempty"`
	Cimb    []int8 `json:"cimb,omitempty"`
	Mega    []int8 `json:"mega,omitempty"`
	Bca     []int8 `json:"bca,omitempty"`
	Bri     []int8 `json:"bri,omitempty"`
	Maybank []int8 `json:"maybank,omitempty"`
	Offline []int8 `json:"offline,omitempty"`
}

InstallmentTermsDetail : Represent installment available banks

type IrisApprovePayoutReq

type IrisApprovePayoutReq struct {
	ReferenceNo []string `json:"reference_nos"`
	OTP         string   `json:"otp"`
}

IrisApprovePayoutReq : Represent Approve Payout payload

type IrisApprovePayoutResponse

type IrisApprovePayoutResponse struct {
	Status       string   `json:"status"`
	ErrorMessage string   `json:"error_message"`
	Errors       []string `json:"errors"`
}

IrisApprovePayoutResponse : Represent Approve payout response payload

type IrisBalanceResponse

type IrisBalanceResponse struct {
	Balance string `json:"balance"`
}

IrisBalanceResponse : Represent balance detail response payload

type IrisBankAccountDetailErrorResponse

type IrisBankAccountDetailErrorResponse struct {
	Account []string `json:"account"`
	Bank    []string `json:"bank"`
}

IrisBankAccountDetailErrorResponse : Represent Bank account detail error payload

type IrisBankAccountDetailResponse

type IrisBankAccountDetailResponse struct {
	AccountName  string                              `json:"account_name"`
	AccountNo    string                              `json:"account_no"`
	BankName     string                              `json:"bank_name"`
	ErrorMessage string                              `json:"error_message"`
	Errors       *IrisBankAccountDetailErrorResponse `json:"errors"`
}

IrisBankAccountDetailResponse : Represent Bank account detail payload

type IrisBeneficiaries

type IrisBeneficiaries struct {
	Name      string `json:"name"`
	Account   string `json:"account"`
	Bank      string `json:"bank"`
	AliasName string `json:"alias_name"`
	Email     string `json:"email"`
}

IrisBeneficiaries : Beneficiaries request (create, update, list) https://iris-docs.midtrans.com/#create-beneficiaries https://iris-docs.midtrans.com/#update-beneficiaries https://iris-docs.midtrans.com/#list-beneficiaries

type IrisBeneficiariesResponse

type IrisBeneficiariesResponse struct {
	Status     string   `json:"status"`
	StatusCode string   `json:"status_code"`
	Errors     []string `json:"errors"`
}

IrisBeneficiariesResponse : Represent Beneficiaries response payload

type IrisBeneficiaryBankResponse

type IrisBeneficiaryBankResponse struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

IrisBeneficiaryBankResponse : Represent Beneficiary bank response payload

type IrisBeneficiaryBanksResponse

type IrisBeneficiaryBanksResponse struct {
	BeneficiaryBanks []IrisBeneficiaryBankResponse `json:"beneficiary_banks"`
	StatusCode       string                        `json:"status_code"`
}

IrisBeneficiaryBanksResponse : Show list of supported banks in IRIS. https://iris-docs.midtrans.com/#list-banks

type IrisCreatePayoutDetailReq

type IrisCreatePayoutDetailReq struct {
	BeneficiaryName    string `json:"beneficiary_name"`
	BeneficiaryAccount string `json:"beneficiary_account"`
	BeneficiaryBank    string `json:"beneficiary_bank"`
	BeneficiaryEmail   string `json:"beneficiary_email"`
	Amount             string `json:"amount"`
	Notes              string `json:"notes"`
}

IrisCreatePayoutDetailReq : Represent Create Payout detail payload

type IrisCreatePayoutDetailResponse

type IrisCreatePayoutDetailResponse struct {
	Status      string `json:"status"`
	ReferenceNo string `json:"reference_no"`
}

IrisCreatePayoutDetailResponse : Represent Create payout detail response payload

type IrisCreatePayoutReq

type IrisCreatePayoutReq struct {
	Payouts []IrisCreatePayoutDetailReq `json:"payouts"`
}

IrisCreatePayoutReq : Represent Create Payout request payload

type IrisCreatePayoutResponse

type IrisCreatePayoutResponse struct {
	Payouts      []IrisCreatePayoutDetailResponse `json:"payouts"`
	ErrorMessage string                           `json:"error_message"`
	Errors       []string                         `json:"errors"`
}

IrisCreatePayoutResponse : Represent Create payout response payload

type IrisGateway

type IrisGateway struct {
	Client Client
}

IrisGateway struct

func (*IrisGateway) ApprovePayouts

func (gateway *IrisGateway) ApprovePayouts(req IrisApprovePayoutReq) (IrisApprovePayoutResponse, error)

ApprovePayouts : Use this API for Apporver to approve multiple payout request. (https://iris-docs.midtrans.com/#approve-payouts)

func (*IrisGateway) Call

func (gateway *IrisGateway) Call(method, path string, body io.Reader, v interface{}) error

Call : base method to call IRIS API

func (*IrisGateway) CheckBalance

func (gateway *IrisGateway) CheckBalance() (IrisBalanceResponse, error)

CheckBalance : Check Balance (Aggregator) (https://iris-docs.midtrans.com/#check-balance-aggregator)

func (*IrisGateway) CreateBeneficiaries

func (gateway *IrisGateway) CreateBeneficiaries(req *IrisBeneficiaries) (bool, error)

CreateBeneficiaries : Create Beneficiaries (https://iris-docs.midtrans.com/#create-beneficiaries)

func (*IrisGateway) CreatePayouts

func (gateway *IrisGateway) CreatePayouts(req IrisCreatePayoutReq) (IrisCreatePayoutResponse, error)

CreatePayouts : This API is for Creator to create a payout. It can be used for single payout and also multiple payouts. (https://iris-docs.midtrans.com/#create-payouts)

func (*IrisGateway) GetListBeneficiaries

func (gateway *IrisGateway) GetListBeneficiaries() ([]IrisBeneficiaries, error)

GetListBeneficiaries : Get List Beneficiaries (https://iris-docs.midtrans.com/#list-beneficiaries)

func (*IrisGateway) GetListBeneficiaryBank

func (gateway *IrisGateway) GetListBeneficiaryBank() (IrisBeneficiaryBanksResponse, error)

GetListBeneficiaryBank : Show list of supported banks in IRIS. (https://iris-docs.midtrans.com/#list-banks)

func (*IrisGateway) GetPayoutDetails

func (gateway *IrisGateway) GetPayoutDetails(referenceNo string) (IrisPayoutDetailResponse, error)

GetPayoutDetails : Get details of a single payout (https://iris-docs.midtrans.com/#get-payout-details)

func (*IrisGateway) GetPayoutHistory

func (gateway *IrisGateway) GetPayoutHistory(fromDate string, toDate string) ([]IrisPayoutDetailResponse, error)

GetPayoutHistory : Returns all the payout details for specific dates (https://iris-docs.midtrans.com/#payout-history)

func (*IrisGateway) RejectPayouts

func (gateway *IrisGateway) RejectPayouts(req IrisRejectPayoutReq) (IrisRejectPayoutResponse, error)

RejectPayouts : Use this API for Apporver to reject multiple payout request. (https://iris-docs.midtrans.com/#reject-payouts)

func (*IrisGateway) UpdateBeneficiaries

func (gateway *IrisGateway) UpdateBeneficiaries(aliasName string, req *IrisBeneficiaries) (bool, error)

UpdateBeneficiaries : Update Beneficiaries (https://iris-docs.midtrans.com/#update-beneficiaries)

func (*IrisGateway) ValidateBankAccount

func (gateway *IrisGateway) ValidateBankAccount(bankName string, accountNo string) (IrisBankAccountDetailResponse, error)

ValidateBankAccount : Check if an account is valid, if valid return account information. (https://iris-docs.midtrans.com/#validate-bank-account)

type IrisPayoutDetailResponse

type IrisPayoutDetailResponse struct {
	Amount             string    `json:"amount"`
	BeneficiaryName    string    `json:"beneficiary_name"`
	BeneficiaryAccount string    `json:"beneficiary_account"`
	Bank               string    `json:"bank"`
	ReferenceNo        string    `json:"reference_no"`
	Notes              string    `json:"notes"`
	BeneficiaryEmail   string    `json:"beneficiary_email"`
	Status             string    `json:"status"`
	CreatedBy          string    `json:"created_by"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	ErrorMessage       string    `json:"error_message"`
	Errors             string    `json:"errors"`
}

IrisPayoutDetailResponse : Represent Payout detail response payload

type IrisRejectPayoutReq

type IrisRejectPayoutReq struct {
	ReferenceNo  []string `json:"reference_nos"`
	RejectReason string   `json:"reject_reason"`
}

IrisRejectPayoutReq : Represent Reject Payout payload

type IrisRejectPayoutResponse

type IrisRejectPayoutResponse struct {
	Status       string   `json:"status"`
	ErrorMessage string   `json:"error_message"`
	Errors       []string `json:"errors"`
}

IrisRejectPayoutResponse : Represent Reject payout response payload

type ItemDetail

type ItemDetail struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Price        int64  `json:"price"`
	Qty          int32  `json:"quantity"`
	Brand        string `json:"brand,omitempty"`
	Category     string `json:"category,omitempty"`
	MerchantName string `json:"merchant_name,omitempty"`
}

ItemDetail : Represent the transaction details

type MandiriBillBankTransferDetail

type MandiriBillBankTransferDetail struct {
	BillInfo1 string `json:"bill_info1,omitempty"`
	BillInfo2 string `json:"bill_info2,omitempty"`
}

MandiriBillBankTransferDetail : Represent Mandiri Bill bank_transfer detail

type MandiriClickPayDetail

type MandiriClickPayDetail struct {
	TokenID string `json:"token_id"`
	Input1  string `json:"input1"`
	Input2  string `json:"input2"`
	Input3  string `json:"input3"`
	Token   string `json:"token"`
}

MandiriClickPayDetail : Represent Mandiri ClickPay detail

type MandiriEcashDetail

type MandiriEcashDetail struct {
	Desc string `json:"description"`
}

MandiriEcashDetail : Represent Mandiri e-Cash detail

type PaymentType

type PaymentType string

PaymentType value

const (
	// SourceBankTransfer : bank_transfer
	SourceBankTransfer PaymentType = "bank_transfer"

	// SourceBNIVA : bni_va
	SourceBNIVA PaymentType = "bni_va"

	// SourcePermataVA : permata_va
	SourcePermataVA PaymentType = "permata_va"

	// SourceBCAVA : bca_va
	SourceBCAVA PaymentType = "bca_va"

	// SourceOtherVA : other_va
	SourceOtherVA PaymentType = "other_va"

	// SourceBcaKlikpay : bca_klikpay
	SourceBcaKlikpay PaymentType = "bca_klikpay"

	// SourceBriEpay : bri_epay
	SourceBriEpay PaymentType = "bri_epay"

	// SourceCreditCard : credit_card
	SourceCreditCard PaymentType = "credit_card"

	// SourceCimbClicks : cimb_clicks
	SourceCimbClicks PaymentType = "cimb_clicks"

	// SourceDanamonOnline : danamon_online
	SourceDanamonOnline PaymentType = "danamon_online"

	// SourceConvStore : cstore
	SourceConvStore PaymentType = "cstore"

	// SourceKlikBca : bca_klikbca
	SourceKlikBca PaymentType = "bca_klikbca"

	// SourceEchannel : echannel
	SourceEchannel PaymentType = "echannel"

	// SourceMandiriClickpay : mandiri_clickpay
	SourceMandiriClickpay PaymentType = "mandiri_clickpay"

	// SourceTelkomselCash : telkomsel_cash
	SourceTelkomselCash PaymentType = "telkomsel_cash"

	// SourceIndosatDompetku : indosat_dompetku
	SourceIndosatDompetku PaymentType = "indosat_dompetku"

	// SourceMandiriEcash : mandiri_ecash
	SourceMandiriEcash PaymentType = "mandiri_ecash"

	// SourceKioson : kioson
	SourceKioson PaymentType = "kioson"

	// SourceIndomaret : indomaret
	SourceIndomaret PaymentType = "indomaret"

	// SourceAlfamart : alfamart
	SourceAlfamart PaymentType = "alfamart"

	// SourceGiftCardIndo : gci
	SourceGiftCardIndo PaymentType = "gci"

	// SourceGopay : gopay
	SourceGopay PaymentType = "gopay"

	// SourceShopeePay : shopeepay
	SourceShopeePay PaymentType = "shopeepay"

	// SourceAkulaku : akulaku
	SourceAkulaku PaymentType = "akulaku"
)

type PermataBankTransferDetail

type PermataBankTransferDetail struct {
	Bank Bank `json:"bank"`
}

PermataBankTransferDetail : Represent Permata bank_transfer detail

type Refund

type Refund struct {
	RefundChargebackID int    `json:"refund_chargeback_id"`
	RefundAmount       string `json:"refund_amount"`
	Reason             string `json:"reason"`
	RefundKey          string `json:"refund_key"`
	RefundMethod       string `json:"refund_method"`
	BankConfirmedAt    string `json:"bank_confirmed_at"`
	CreatedAt          string `json:"created_at"`
}

Refund Details

type RefundReq

type RefundReq struct {
	RefundKey string `json:"refund_key"`
	Amount    int64  `json:"amount"`
	Reason    string `json:"reason"`
}

RefundReq : Represent Refund request payload

type Response

type Response struct {
	StatusCode           string     `json:"status_code"`
	StatusMessage        string     `json:"status_message"`
	PermataVaNumber      string     `json:"permata_va_number"`
	SignKey              string     `json:"signature_key"`
	CardToken            string     `json:"token_id"`
	SavedCardToken       string     `json:"saved_token_id"`
	SavedTokenExpAt      string     `json:"saved_token_id_expired_at"`
	SecureToken          bool       `json:"secure_token"`
	Bank                 string     `json:"bank"`
	BillerCode           string     `json:"biller_code"`
	BillKey              string     `json:"bill_key"`
	XlTunaiOrderID       string     `json:"xl_tunai_order_id"`
	BIIVaNumber          string     `json:"bii_va_number"`
	ReURL                string     `json:"redirect_url"`
	ECI                  string     `json:"eci"`
	ValMessages          []string   `json:"validation_messages"`
	Page                 int        `json:"page"`
	TotalPage            int        `json:"total_page"`
	TotalRecord          int        `json:"total_record"`
	FraudStatus          string     `json:"fraud_status"`
	PaymentType          string     `json:"payment_type"`
	OrderID              string     `json:"order_id"`
	TransactionID        string     `json:"transaction_id"`
	TransactionTime      string     `json:"transaction_time"`
	TransactionStatus    string     `json:"transaction_status"`
	GrossAmount          string     `json:"gross_amount"`
	VANumbers            []VANumber `json:"va_numbers"`
	PaymentCode          string     `json:"payment_code"`
	Store                string     `json:"store"`
	MerchantID           string     `json:"merchant_id"`
	MaskedCard           string     `json:"masked_card"`
	Currency             string     `json:"currency"`
	CardType             string     `json:"card_type"`
	Actions              []Action   `json:"actions"`
	RefundChargebackID   int        `json:"refund_chargeback_id"`
	RefundAmount         string     `json:"refund_amount"`
	RefundKey            string     `json:"refund_key"`
	Refunds              []Refund   `json:"refunds"`
	ChannelResponseCode  string     `json:"channel_response_code"`
	ChannelStatusMessage string     `json:"channel_status_message"`
}

Response after calling the API

type ResponseWithMap

type ResponseWithMap map[string]interface{}

ResponseWithMap after calling the API

type ScheduleDetailReq

type ScheduleDetailReq struct {
	Interval     int    `json:"interval"`
	MaxInterval  int    `json:"max_interval"`
	IntervalUnit string `json:"interval_unit"`
	StartTime    string `json:"start_time"`
}

ScheduleDetailReq : Represent Schedule object payload

type ScheduleDetailResponse

type ScheduleDetailResponse struct {
	Interval            int    `json:"interval"`
	IntervalUnit        string `json:"interval_unit"`
	StartTime           string `json:"start_time"`
	PreviousExecutionAt string `json:"previous_execution_at"`
	NextExecutionAt     string `json:"next_execution_at"`
}

type ShopeePayDetail

type ShopeePayDetail struct {
	CallbackUrl string `json:"callback_url,omitempty"`
}

ShopeePayDetail : Represent shopeepay detail

type SnapGateway

type SnapGateway struct {
	Client Client
}

SnapGateway struct

func (*SnapGateway) Call

func (gateway *SnapGateway) Call(method, path string, body io.Reader, v interface{}) error

Call : base method to call Snap API

func (*SnapGateway) GetToken

func (gateway *SnapGateway) GetToken(r *SnapReq) (SnapResponse, error)

GetToken : Get token by consuming SnapReq

func (*SnapGateway) GetTokenQuick

func (gateway *SnapGateway) GetTokenQuick(orderID string, grossAmount int64) (SnapResponse, error)

GetTokenQuick : Quickly get token without constructing the body manually

func (*SnapGateway) GetTokenQuickWithMap

func (gateway *SnapGateway) GetTokenQuickWithMap(orderID string, grossAmount int64) (ResponseWithMap, error)

GetTokenQuickWithMap : Quickly get token without constructing the body manually

func (*SnapGateway) GetTokenWithMap

func (gateway *SnapGateway) GetTokenWithMap(r *SnapReqWithMap) (ResponseWithMap, error)

GetTokenWithMap : Get token by consuming SnapReqWithMap

type SnapReq

type SnapReq struct {
	TransactionDetails TransactionDetails `json:"transaction_details"`
	EnabledPayments    []PaymentType      `json:"enabled_payments,omitempty"`
	Callbacks          *Callbacks         `json:"callbacks"`
	Items              *[]ItemDetail      `json:"item_details,omitempty"`
	CustomerDetail     *CustDetail        `json:"customer_details,omitempty"`
	Expiry             *ExpiryDetail      `json:"expiry,omitempty"`
	CreditCard         *CreditCardDetail  `json:"credit_card,omitempty"`
	Gopay              *GopayDetail       `json:"gopay,omitempty"`
	ShopeePay          *ShopeePayDetail   `json:"shopeepay,omitempty"`
	UserId             string             `json:"user_id,omitempty"`
	CustomField1       string             `json:"custom_field1,omitempty"`
	CustomField2       string             `json:"custom_field2,omitempty"`
	CustomField3       string             `json:"custom_field3,omitempty"`
}

SnapReq : Represent SNAP API request payload

type SnapReqWithMap

type SnapReqWithMap map[string]interface{}

SnapReqWithMap : Represent snap request with map payload

type SnapResponse

type SnapResponse struct {
	StatusCode    string   `json:"status_code"`
	Token         string   `json:"token"`
	RedirectURL   string   `json:"redirect_url"`
	ErrorMessages []string `json:"error_messages"`
}

SnapResponse : Response after calling the Snap API

type SubscribeReq

type SubscribeReq struct {
	Name        string            `json:"name"`
	Amount      string            `json:"amount"`
	Currency    string            `json:"currency"`
	Token       string            `json:"token"`
	PaymentType PaymentType       `json:"payment_type"`
	Schedule    ScheduleDetailReq `json:"schedule"`
}

SubscribeReq : Represent Subscribe object payload (request and response)

type SubscribeResponse

type SubscribeResponse struct {
	ID             string                 `json:"id"`
	CreatedAt      string                 `json:"created_at"`
	Status         string                 `json:"status"`
	Name           string                 `json:"name"`
	Amount         string                 `json:"amount"`
	Currency       string                 `json:"currency"`
	Token          string                 `json:"token"`
	PaymentType    PaymentType            `json:"payment_type"`
	Schedule       ScheduleDetailResponse `json:"schedule"`
	StatusMessage  string                 `json:"status_message"`
	TransactionIDs []string               `json:"transaction_ids"`
}

type TelkomselCashDetail

type TelkomselCashDetail struct {
	Promo      bool   `json:"promo"`
	IsReversal int8   `json:"is_reversal"`
	Customer   string `json:"customer"`
}

TelkomselCashDetail : Represent Telkomsel Cash detail

type TransactionDetails

type TransactionDetails struct {
	OrderID  string `json:"order_id"`
	GrossAmt int64  `json:"gross_amount"`
}

TransactionDetails : Represent transaction details

type VANumber

type VANumber struct {
	Bank     string `json:"bank"`
	VANumber string `json:"va_number"`
}

VANumber : bank virtual account number

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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