snap

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 5 Imported by: 35

Documentation

Index

Constants

This section is empty.

Variables

AllSnapPaymentType : Get All available SnapPaymentType

Functions

func CreateTransactionToken

func CreateTransactionToken(req *Request) (string, *midtrans.Error)

CreateTransactionToken : Do `/transactions` API request to SNAP API to get Snap token with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func CreateTransactionTokenWithMap

func CreateTransactionTokenWithMap(req *RequestParamWithMap) (string, *midtrans.Error)

CreateTransactionTokenWithMap : Do `/transactions` API request to SNAP API to get Snap token with map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func CreateTransactionUrl

func CreateTransactionUrl(req *Request) (string, *midtrans.Error)

CreateTransactionUrl : Do `/transactions` API request to SNAP API to get Snap redirect url with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func CreateTransactionUrlWithMap

func CreateTransactionUrlWithMap(req *RequestParamWithMap) (string, *midtrans.Error)

CreateTransactionUrlWithMap : Do `/transactions` API request to SNAP API to get Snap redirect url with map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

Types

type BcaVa

type BcaVa struct {
	// VaNumber : Custom VA Number, Length should be within 1 to 11.
	// https://snap-docs.midtrans.com/#custom-virtual-account-number
	VaNumber       string `json:"va_number,omitempty"`
	SubCompanyCode string `json:"sub_company_code,omitempty"`
	FreeText       struct {
		Inquiry []struct {
			En string `json:"en"`
			Id string `json:"id"`
		} `json:"inquiry,omitempty"`
		Payment []struct {
			En string `json:"en"`
			Id string `json:"id"`
		} `json:"payment,omitempty"`
	} `json:"free_text,omitempty"`
}

BcaVa : BCA Virtual Account is a virtual payment method offered by Bank BCA. https://snap-docs.midtrans.com/#bca-virtual-account

type BniVa

type BniVa struct {
	// VaNumber : Custom VA Number, Length should be within 1 to 8.
	// https://snap-docs.midtrans.com/#custom-virtual-account-number
	VaNumber string `json:"va_number,omitempty"`
}

BniVa : BNI Virtual Account is a virtual payment method offered by Bank BNI. https://snap-docs.midtrans.com/#bni-virtual-account

type BriVa

type BriVa struct {
	// VaNumber : Custom VA Number, Length should be within 1 to 13.
	// https://snap-docs.midtrans.com/#custom-virtual-account-number
	VaNumber string `json:"va_number,omitempty"`
}

BriVa : BRI Virtual Account is a virtual payment method offered by Bank BRI. https://snap-docs.midtrans.com/#bri-virtual-account

type Callbacks

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

Callbacks : Redirect URL after transaction is successfully paid (Overridden by JS callback). Can also be set via Snap Settings menu in your dashboard.

type Client

type Client struct {
	ServerKey  string
	Env        midtrans.EnvironmentType
	HttpClient midtrans.HttpClient
	Options    *midtrans.ConfigOptions
}

Client : Snap Client struct

func (Client) CreateTransaction

func (c Client) CreateTransaction(req *Request) (*Response, *midtrans.Error)

CreateTransaction : Do `/transactions` API request to SNAP API to get Snap token and redirect url with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (Client) CreateTransactionToken

func (c Client) CreateTransactionToken(req *Request) (string, *midtrans.Error)

CreateTransactionToken : Do `/transactions` API request to SNAP API to get Snap token with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (Client) CreateTransactionTokenWithMap

func (c Client) CreateTransactionTokenWithMap(req *RequestParamWithMap) (string, *midtrans.Error)

CreateTransactionTokenWithMap : Do `/transactions` API request to SNAP API to get Snap token with map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (Client) CreateTransactionUrl

func (c Client) CreateTransactionUrl(req *Request) (string, *midtrans.Error)

CreateTransactionUrl : Do `/transactions` API request to SNAP API to get Snap redirect url with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (Client) CreateTransactionUrlWithMap

func (c Client) CreateTransactionUrlWithMap(req *RequestParamWithMap) (string, *midtrans.Error)

CreateTransactionUrlWithMap : Do `/transactions` API request to SNAP API to get Snap redirect url with map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (Client) CreateTransactionWithMap

func (c Client) CreateTransactionWithMap(req *RequestParamWithMap) (ResponseWithMap, *midtrans.Error)

CreateTransactionWithMap : Do `/transactions` API request to SNAP API return RAW JSON with Map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

func (*Client) New

func (c *Client) New(serverKey string, env midtrans.EnvironmentType)

New : this function will always be called when the Snap is initiated

type CreditCardDetails

type CreditCardDetails struct {
	// indicate if generated token should be saved for next charge
	SaveCard bool `json:"save_card,omitempty"`

	// Use 3D-Secure authentication when using credit card. Default: false
	Secure bool `json:"secure,omitempty"`

	// Acquiring bank. Valid values: `midtrans.BankBca` `midtrans.BankMandiri`, `midtrans.BankBni`,
	//`midtrans.BankCimb`, `midtrans.BankMaybank`, and `midtrans.BankBri`
	Bank string `json:"bank,omitempty"`

	// Acquiring channel. Options: migs
	Channel string `json:"channel,omitempty"`

	// Credit card transaction type. Options: authorize, authorize_capture. Default: “authorize_capture”
	Type string `json:"type,omitempty"`

	// Snap for installment detail
	Installment *InstallmentDetail `json:"installment,omitempty"`

	// Allowed credit card BIN numbers.
	// The bin value can be either a prefix(upto 8 digits) of card number or the name of a bank,
	// in which case all the cards issued by that bank will be allowed.
	// The supported bank names are bni bca mandiri cimb bri and maybank. Default: allow all cards
	WhitelistBins []string `json:"whitelist_bins,omitempty"`

	DynamicDescriptor *DynamicDescriptor `json:"dynamic_descriptor,omitempty"`

	CardToken string `json:"card_token,omitempty"`
}

CreditCardDetails : Represent credit card detail for PaymentTypeCreditCard payment type

type Cstore

type Cstore struct {
	AlfamartFreeText1 string `json:"alfamart_free_text_1,omitempty"`
	AlfamartFreeText2 string `json:"alfamart_free_text_2,omitempty"`
	AlfamartFreeText3 string `json:"alfamart_free_text_3,omitempty"`
}

Cstore : Cstore object is for PaymentTypeAlfamart free text

type DynamicDescriptor

type DynamicDescriptor struct {
	// First 25 digit on customer’s billing statement. Mostly used to show the merchant or product name.
	// Only works for BNI.
	MerchantName string `json:"merchant_name,omitempty"`

	// Next 13 digit on customer’s billing statement. It works as secondary metadata on the statement.
	// Mostly used to show city name or region. Only works for BNI.
	CityName string `json:"city_name,omitempty"`

	// Last 2 digit on customer’s billing statement. Mostly used to show country code.
	// The format is ISO 3166-1 alpha-2. Only works for BNI.
	CountryCode string `json:"country_code,omitempty"`
}

type ExpiryDetails

type ExpiryDetails struct {
	// StartTime : Timestamp in yyyy-MM-dd HH:mm:ss Z format. If not specified,
	// transaction time will be used as start time (when customer charge)
	StartTime string `json:"start_time,omitempty"`

	// Unit Expiry unit. Options: day, hour, minute (plural term also accepted)
	Unit string `json:"unit"`

	// Duration Expiry duration
	Duration int64 `json:"duration"`
}

ExpiryDetails : Represent SNAP expiry details

type GopayDetails

type GopayDetails struct {
	// EnableCallback : Enable redirect back to merchant from GoJek apps. Default: false
	EnableCallback bool `json:"enable_callback,omitempty"`

	// CallbackUrl : Determine where should customer be redirected from GoJek apps.
	// It supports both HTTP and deeplink. Default: same value as finish url
	CallbackUrl string `json:"callback_url,omitempty"`
}

GopayDetails : Represent gopay detail

type InstallmentDetail

type InstallmentDetail struct {
	// Force installment when using credit card. Default: false
	Required bool `json:"required,omitempty"`

	// Available installment terms
	Terms *InstallmentTermsDetail `json:"terms,omitempty"`
}

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 PermataVa

type PermataVa struct {
	// VaNumber : Custom VA Number, Length should be 10. Only supported for b2b transactions.
	// https://snap-docs.midtrans.com/#custom-virtual-account-number
	VaNumber      string `json:"va_number,omitempty"`
	RecipientName string `json:"recipient_name,omitempty"`
}

PermataVa : Permata Virtual Account is a virtual payment method offered by Bank Permata. https://snap-docs.midtrans.com/#permata-virtual-account

type Request

type Request struct {
	TransactionDetails midtrans.TransactionDetails `json:"transaction_details"`
	Items              *[]midtrans.ItemDetails     `json:"item_details,omitempty"`
	CustomerDetail     *midtrans.CustomerDetails   `json:"customer_details,omitempty"`
	EnabledPayments    []SnapPaymentType           `json:"enabled_payments,omitempty"`
	CreditCard         *CreditCardDetails          `json:"credit_card,omitempty"`
	BcaVa              *BcaVa                      `json:"bca_va,omitempty"`
	BniVa              *BniVa                      `json:"bni_va,omitempty"`
	BriVa              *BriVa                      `json:"bri_va,omitempty"`
	PermataVa          *PermataVa                  `json:"permata_va,omitempty"`
	Gopay              *GopayDetails               `json:"gopay,omitempty"`
	ShopeePay          *ShopeePayDetails           `json:"shopeepay,omitempty"`
	Callbacks          *Callbacks                  `json:"callbacks,omitempty"`
	Expiry             *ExpiryDetails              `json:"expiry,omitempty"`
	UserId             string                      `json:"user_id,omitempty"`
	Cstore             *Cstore                     `json:"cstore,omitempty"`
	CustomField1       string                      `json:"custom_field1,omitempty"`
	CustomField2       string                      `json:"custom_field2,omitempty"`
	CustomField3       string                      `json:"custom_field3,omitempty"`
	Metadata           interface{}                 `json:"metadata,omitempty"`
}

Request : Represent SNAP API request payload that are used in Create Snap Token parameter. https://snap-docs.midtrans.com/#json-objects

type RequestParamWithMap

type RequestParamWithMap map[string]interface{}

RequestParamWithMap SnapReqWithMap : Represent snap request with map payload

type Response

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

Response : Snap response after calling the Snap API

func CreateTransaction

func CreateTransaction(req *Request) (*Response, *midtrans.Error)

CreateTransaction : Do `/transactions` API request to SNAP API to get Snap token and redirect url with `snap.Request` as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

type ResponseWithMap

type ResponseWithMap map[string]interface{}

ResponseWithMap : Snap response with map after calling the Snap API

func CreateTransactionWithMap

func CreateTransactionWithMap(req *RequestParamWithMap) (ResponseWithMap, *midtrans.Error)

CreateTransactionWithMap : Do `/transactions` API request to SNAP API to get Snap token and redirect url with map as body parameter, will be converted to JSON, more detail refer to: https://snap-docs.midtrans.com

type ShopeePayDetails

type ShopeePayDetails struct {
	// CallbackUrl : Determine where should customer be redirected from Shopee apps.
	// It supports both HTTP and deeplink. Default: same value as finish url, if it’s also empty,
	// it will be redirected to default payment processed page
	CallbackUrl string `json:"callback_url,omitempty"`
}

ShopeePayDetails : Represent shopeepay detail

type SnapPaymentType

type SnapPaymentType string
const (
	// PaymentTypeCreditCard : credit_card
	PaymentTypeCreditCard SnapPaymentType = "credit_card"

	// PaymentTypeMandiriClickpay : mandiri_clickpay
	PaymentTypeMandiriClickpay SnapPaymentType = "mandiri_clickpay"

	// PaymentTypeCimbClicks : cimb_clicks
	PaymentTypeCimbClicks SnapPaymentType = "cimb_clicks"

	// PaymentTypeKlikBca : bca_klikbca
	PaymentTypeKlikBca SnapPaymentType = "bca_klikbca"

	// PaymentTypeBCAKlikpay : bca_klikpay
	PaymentTypeBCAKlikpay SnapPaymentType = "bca_klikpay"

	// PaymentTypeBRIEpay : bri_epay
	PaymentTypeBRIEpay SnapPaymentType = "bri_epay"

	// PaymentTypeTelkomselCash : telkomsel_cash
	PaymentTypeTelkomselCash SnapPaymentType = "telkomsel_cash"

	// PaymentTypeEChannel : echannel
	PaymentTypeEChannel SnapPaymentType = "echannel"

	// PaymentTypeMandiriEcash : mandiri_ecash
	PaymentTypeMandiriEcash SnapPaymentType = "mandiri_ecash"

	// PaymentTypePermataVA : permata_va
	PaymentTypePermataVA SnapPaymentType = "permata_va"

	// PaymentTypeOtherVA : other_va If you want to use other_va, either permata_va or bni_va
	// because Midtrans handles other bank transfer as either Permata or BNI VA.
	PaymentTypeOtherVA SnapPaymentType = "other_va"

	// PaymentTypeBCAVA : bca_va
	PaymentTypeBCAVA SnapPaymentType = "bca_va"

	// PaymentTypeBNIVA : bni_va
	PaymentTypeBNIVA SnapPaymentType = "bni_va"

	// PaymentTypeBRIVA : bca_va
	PaymentTypeBRIVA SnapPaymentType = "bri_va"

	// PaymentTypeBankTransfer : bank_transfer
	PaymentTypeBankTransfer SnapPaymentType = "bank_transfer"

	// PaymentTypeConvenienceStore : cstore
	PaymentTypeConvenienceStore SnapPaymentType = "cstore"

	// PaymentTypeIndomaret : indomaret
	PaymentTypeIndomaret SnapPaymentType = "indomaret"

	// PaymentTypeKioson : kioson
	PaymentTypeKioson SnapPaymentType = "kioson"

	// PaymentTypeDanamonOnline : danamon_online
	PaymentTypeDanamonOnline SnapPaymentType = "danamon_online"

	// PaymentTypeAkulaku : akulaku
	PaymentTypeAkulaku SnapPaymentType = "akulaku"

	// PaymentTypeGopay : gopay
	PaymentTypeGopay SnapPaymentType = "gopay"

	// PaymentTypeShopeepay : shopeepay
	PaymentTypeShopeepay SnapPaymentType = "shopeepay"

	// PaymentTypeAlfamart : alfamart
	PaymentTypeAlfamart SnapPaymentType = "alfamart"
)

Jump to

Keyboard shortcuts

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