yuansfer

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

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

Go to latest
Published: Nov 17, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

Yuansfer

golang_sdk Build Status GoDoc

yuansfer SDK for golang

about

  • Use yuansfer.LoadConfiguration(y yuansfer.Configuration) function to setup credentials
[credentials]
store_no = "3xxxxx"
merchant_no = "2xxxxx"
environment = "sandbox" # production
token = "obtain your developer token from yuansfer portal"

import "github.com/yuansfer/golang_sdk"

package main

import "fmt"
import "time"

import "github.com/yuansfer/golang_sdk"

func securePay() {
	req := &yuansfer.SecurePay{
		Currency:       "USD",
		SettleCurrency: "USD",
		Amount:         "1.99",
		Vendor:         "alipay",
		Reference:      fmt.Sprintf("%s-%d", "alipay", time.Now().Unix()),
		Terminal:       "ONLINE",
		IpnURL:         "https://t.ldf.fit/callback",
		CallbackURL:    "https://t.ldf.fit/callback",
		Note:           "123",
		Description:    "456",
		//Timeout:        "",
		//GoodsInfo:      "",
		//CreditType:     "",
		//CustomerNo:     "",
		//OSType:         "",
	}

	buf, err := req.PostToYuansfer()
	if nil != err {
		fmt.Println("failed: ", err.Error())
	} else {
		fmt.Println("response ==> ", string(buf))
	}
}

contact us

Documentation

Overview

Package yuansfer the golang SDK for Yuansfer Payment API.

Index

Constants

View Source
const (
	URISecurePay    = "/online/v3/secure-pay"
	URIYipApp       = "/micropay/v3/prepay"
	URIYipProcess   = "/creditpay/v3/process"
	URIRefund       = "/app-data-search/v3/refund"
	URICancel       = "/app-data-search/v3/cancel"
	URIRetrieve     = "/app-data-search/v3/tran-query"
	URIPosAdd       = "/app-instore/v3/add"
	URIPosPay       = "/app-instore/v3/pay"
	URIPosCreateQRC = "/app-instore/v3/create-trans-qrcode"

	GatewaySandbox    = "https://mapi.yuansfer.yunkeguan.com"
	GatewayProduction = "https://mapi.yuansfer.com"
)

Variables

View Source
var (
	//Development or Production domain
	APIGateway string

	// token obtained from Yuansfer portal
	Token string

	Cred = make(map[string]string)
)

Functions

func LoadConfiguration

func LoadConfiguration(c Configuration)

func VerifySignNotify

func VerifySignNotify(values url.Values, token string) (m map[string]string, r bool)

VerifySignNotify checks the parameters from Yuansfer with the value of verifySign.

func Version

func Version() string

Version is the current release version.

Types

type AddResponse

type AddResponse struct {
	Result      string `json:"ret_code"`
	RetMsg      string `json:"ret_msg"`
	Transaction AddRet `json:"transaction"`
}

AddResponse is the Response from the Yuansfer service.

type AddRet

type AddRet struct {
	TransactionNo         string `json:"transactionNo"`
	OriginalTransactionNo string `json:"originalTransactionNo"`
	MerchantNo            string `json:"merchantNo"`
	StoreNo               string `json:"storeNo"`
	StoreAdminNo          string `json:"storeAdminNo"`
	Amount                string `json:"amount"`
	RefundAmount          string `json:"refundAmount"`
	TransactionType       string `json:"transactionType"`
	TransactionStatus     string `json:"transactionStatus"`
	Currency              string `json:"currency"`
	CreateTime            string `json:"createTime"`
	PaymentTime           string `json:"paymentTime"`
	ExchangeRate          string `json:"exchangeRate"`
	Vendor                string `json:"vendor"`
}

AddRet is the Response from the Yuansfer service.

type Cancel

type Cancel struct {
	GroupNo       string `json:"merGroupNo,omitempty"`
	MerchantNo    string `json:"merchantNo"`
	StoreNo       string `json:"storeNo"`
	VerifySign    string `json:"verifySign"`
	Reference     string `json:"reference,omitempty"`
	TransactionNo string `json:"transactionNo,omitempty"`
}

Cancel to cancel/reverse a transaction

func (*Cancel) LoadCredentials

func (c *Cancel) LoadCredentials()

func (Cancel) PostToYuansfer

func (c Cancel) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer service

type Client

type Client struct {
	URI        string
	HTTPStatus int
	// Body indicates both Request Body & Response Body
	Body []byte
}

func NewHttpClient

func NewHttpClient(uri string, b []byte) *Client

func (*Client) Request

func (c *Client) Request() (err error)

type Configuration

type Configuration struct {
	Credential Credential `toml:"credentials"`
	Network    Network    `toml:"http"`
}

type CreateQrcode

type CreateQrcode struct {
	GroupNo      string `json:"merGroupNo,omitempty"`
	MerchantNo   string `json:"merchantNo"`
	StoreNo      string `json:"storeNo"`
	VerifySign   string `json:"verifySign"`
	Amount       string `json:"amount"`
	StoreAdminNo string `json:"storeAdminNo"`
	Currency     string `json:"currency"`
	Vendor       string `json:"vendor"`
	Reference    string `json:"reference"`
	IpnURL       string `json:"ipnUrl"`
}

CreateQrcode is uesed to create transaction and get QR code for customers to scan to pay

func (*CreateQrcode) LoadCredentials

func (s *CreateQrcode) LoadCredentials()

func (CreateQrcode) PostToYuansfer

func (s CreateQrcode) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type Credential

type Credential struct {
	MerchantNo string `toml:"merchant_no"`
	StoreNo    string `toml:"store_no"`
	Token      string `toml:"token"`
	Env        string `toml:"environment"`
	PartnerNo  string `toml:"partner_no"`
}

type GoodsInformation

type GoodsInformation struct {
	GoodsName string `json:"goods_name"`
	Quantity  string `json:"quantity"`
}

GoodsInformation is a JSON encoded string of an array of items that the customer purchases from the merchant. Special characters are not supported. e.g.: [{"goods_name":"name1","quantity":"quantity1"},{"goods_name":"name2","quantity":"quantity2"}]

type InStoreAdd

type InStoreAdd struct {
	GroupNo      string `json:"merGroupNo,omitempty"`
	MerchantNo   string `json:"merchantNo"`
	StoreNo      string `json:"storeNo"`
	VerifySign   string `json:"verifySign"`
	Amount       string `json:"amount"`
	StoreAdminNo string `json:"storeAdminNo"`
	IpnUrl       string `json:"ipnUrl"`
	Reference    string `json:"reference"`
}

InStoreAdd initiates a Barcode/QR Code Payment request and creates a transaction order.

func (*InStoreAdd) LoadCredentials

func (s *InStoreAdd) LoadCredentials()

func (InStoreAdd) PostToYuansfer

func (s InStoreAdd) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type InStorePay

type InStorePay struct {
	GroupNo        string `json:"merGroupNo,omitempty"`
	MerchantNo     string `json:"merchantNo"`
	StoreNo        string `json:"storeNo"`
	VerifySign     string `json:"verifySign"`
	PaymentBarcode string `json:"paymentBarcode"`
	StoreAdminNo   string `json:"storeAdminNo"`
	TransactionNo  string `json:"transactionNo"`
	Vendor         string `json:"vendor"`
}

InStorePay to complete the QRC payment added previously.

func (*InStorePay) LoadCredentials

func (s *InStorePay) LoadCredentials()

func (InStorePay) PostToYuansfer

func (s InStorePay) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type Network

type Network struct {
	RequestTimeout time.Duration `toml:"request_timeout"`
	ConnectTimeout time.Duration `toml:"connect_timeout"`
	SocketTimeout  time.Duration `toml:"socket_timeout"`
}

Network contains common configuration.

type PayResponse

type PayResponse struct {
	Result      string `json:"ret_code"`
	RetMsg      string `json:"ret_msg"`
	Transaction AddRet `json:"transaction"`
}

PayResponse is the response from the Yuansfer service.

type PayRet

type PayRet struct {
	TransactionNo         string `json:"transactionNo"`
	OriginalTransactionNo string `json:"originalTransactionNo"`
	MerchantNo            string `json:"merchantNo"`
	StoreNo               string `json:"storeNo"`
	StoreAdminNo          string `json:"storeAdminNo"`
	Amount                string `json:"amount"`
	RefundAmount          string `json:"refundAmount"`
	TransactionType       string `json:"transactionType"`
	TransactionStatus     string `json:"transactionStatus"`
	Currency              string `json:"currency"`
	CreateTime            string `json:"createTime"`
	PaymentTime           string `json:"paymentTime"`
	ExchangeRate          string `json:"exchangeRate"`
	Vendor                string `json:"vendor"`
}

PayRet is the response from the Yuansfer service.

type Prepay

type Prepay struct {
	GroupNo        string `json:"merGroupNo,omitempty"`
	MerchantNo     string `json:"merchantNo"`
	StoreNo        string `json:"storeNo"`
	VerifySign     string `json:"verifySign"`
	Currency       string `json:"currency"`
	SettleCurrency string `json:"settleCurrency"`
	Amount         string `json:"amount"`
	Vendor         string `json:"vendor"` // Vendor, possible values are alipay, wechatpay
	Reference      string `json:"reference"`
	IpnURL         string `json:"ipnUrl"` // InpURL The instant Payment Notification Handler URL. IPN URL must be secure.
	Description    string `json:"description"`
	Note           string `json:"note"`
	Terminal       string `json:"terminal"` // Terminal including MINIPROGRAM, APP
	Timeout        string `json:"timeout"`
	Openid         string `json:"openid,omitempty"`
}

Prepay does the mobile payment for the In-APP and/or WeChat Mini program solutions.

func (*Prepay) LoadCredentials

func (p *Prepay) LoadCredentials()

func (Prepay) PostToYuansfer

func (p Prepay) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type Process

type Process struct {
	GroupNo    string `json:"merGroupNo"`
	MerchantNo string `json:"merchantNo"`
	StoreNo    string `json:"storeNo"`
	VerifySign string `json:"verifySign"`
	// PaymentMethodNonce received from user end.
	PaymentMethodNonce string `json:"paymentMethodNonce"`
	// PaymentMethod indicates which payment method client selected,
	// accessible values: paypal_account, venmo_account, credit_card, android_pay_card, apple_pay_card
	PaymentMethod string `json:"paymentMethod"`
	TransactionNo string `json:"transactionNo"`
	CustomerNo    string `json:"customerNo,omitempty"`
	// DeviceData received from user end provided by Braintree JS-SDK
	DeviceData string `json:"deviceData"`
}

func (*Process) LoadCredentials

func (p *Process) LoadCredentials()

func (Process) PostToYuansfer

func (p Process) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type QrcodeRet

type QrcodeRet struct {
	Reference     string `json:"reference"`
	RectCode      string `json:"ret_code"`
	DeepLink      string `json:"deepLink"`
	TransactionNo string `json:"transactionNo"`
	TimeOut       string `json:"timeout"`
	QrcodeURL     string `json:"qrcodeUrl"`
}

QrcodeRet is the Response from the Yuansfer service

type QryResponse

type QryResponse struct {
	Result Ret    `json:"result"`
	RetMsg string `json:"ret_msg"`
}

QryResponse is the response from the Yuansfer service.

type QryReverse

type QryReverse struct {
	RetCode string     `json:"ret_code"`
	RetMsg  string     `json:"ret_msg"`
	Result  ReverseRet `json:"refundTransaction"`
}

QryReverse is the response from the Yuansfer service.

type Query

type Query struct {
	GroupNo       string `json:"merGroupNo,omitempty"`
	MerchantNo    string `json:"merchantNo"`
	StoreNo       string `json:"storeNo"`
	VerifySign    string `json:"verifySign"`
	Reference     string `json:"reference,omitempty"`
	TransactionNo string `json:"transactionNo,omitempty"`
}

Query obtain transaction details by ID of the transaction in the merchant’s system.

func (*Query) LoadCredentials

func (q *Query) LoadCredentials()

func (Query) PostToYuansfer

func (q Query) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type Refund

type Refund struct {
	GroupNo    string `json:"merGroupNo,omitempty"`
	MerchantNo string `json:"merchantNo"`
	StoreNo    string `json:"storeNo"`
	VerifySign string `json:"verifySign"`
	Amount     string `json:"refundAmount"`
	Currency   string `json:"currency"`
	// Reference indicates the payment transaction id.
	Reference     string `json:"reference,omitempty"`
	TransactionNo string `json:"transactionNo,omitempty"`
	// RefundReference used for refund transaction
	RefundReference string `json:"refundReference,omitempty"`
	SettleCurrency  string `json:"settleCurrency,omitempty"`
}

Refund To refund payments.

func (*Refund) LoadCredentials

func (r *Refund) LoadCredentials()

func (Refund) PostToYuansfer

func (r Refund) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

type RefundBody

type RefundBody struct {
	OldTransactionID    string `json:"oldTransactionId"`
	RefundTransactionID string `json:"refundTransactionId"`
	Reference           string `json:"reference"`
	Status              string `json:"status"`
}

RefundBody is the response from the Yuansfer service.

type RefundResponse

type RefundResponse struct {
	Result  RefundBody `json:"result"`
	RetMsg  string     `json:"ret_msg"`
	RetCode string     `json:"ret_code"`
}

RefundResponse is the response from the Yuansfer service.

type Ret

type Ret struct {
	Reference  string       `json:"reference"`
	YuansferID string       `json:"yuansferId"`
	Amount     string       `json:"amount"`
	Status     string       `json:"status"`
	RefundInfo []refundInfo `json:"refundInfo"`
	Currency   string       `json:"currency"`
}

Ret is the response from the Yuansfer service.

type ReverseRet

type ReverseRet struct {
	ExchangeRate          string `json:"exchangeRate"`
	Currency              string `json:"currency"`
	Amount                string `json:"amount"`
	CreateTime            string `json:"createTime"`
	MerchantNo            string `json:"merchantNo"`
	OriginalTransactionNo string `json:"originalTransactionNo"`
	PaymentTime           string `json:"paymentTime"`
	RefundAmount          string `json:"refundAmount"`
	StoreAdminNo          string `json:"storeAdminNo"`
	StoreNo               string `json:"storeNo"`
	TransactionNo         string `json:"transactionNo"`
	TransactionStatus     string `json:"transactionStatus"`
	TransactionType       string `json:"transactionType"`
	Reference             string `json:"reference"`
}

ReverseRet is the response from the Yuansfer service.

type SecurePay

type SecurePay struct {
	GroupNo    string `json:"merGroupNo,omitempty"`
	MerchantNo string `json:"merchantNo"`
	StoreNo    string `json:"storeNo"`
	VerifySign string `json:"verifySign"`
	Currency   string `json:"currency"`
	// SettleCurrency refers to settlement currency, default value is USD
	SettleCurrency string `json:"settleCurrency,omitempty"`
	Amount         string `json:"amount"`
	Vendor         string `json:"vendor"`
	Reference      string `json:"reference"`
	Terminal       string `json:"terminal"`
	IpnURL         string `json:"ipnUrl"`
	CallbackURL    string `json:"callbackUrl,omitempty"`
	Note           string `json:"note,omitempty"`
	Description    string `json:"description,omitempty"`
	Timeout        string `json:"timeout,omitempty"`
	GoodsInfo      string `json:"goodsInfo,omitempty"`
	CreditType     string `json:"creditType,omitempty"`
	CustomerNo     string `json:"customerNo,omitempty"`
	OSType         string `json:"osType,omitempty"` // IOS, ANDROID available
}

SecurePay contains the attributes of online payment request.

func (*SecurePay) Format

func (s *SecurePay) Format(goodsInfos []GoodsInformation) (err error)

Format changes GoodsInfo to string.

func (*SecurePay) LoadCredentials

func (s *SecurePay) LoadCredentials()

func (SecurePay) PostToYuansfer

func (s SecurePay) PostToYuansfer() ([]byte, error)

PostToYuansfer is for api call to the Yuansfer gateway

func (*SecurePay) SetCredidentails

func (s *SecurePay) SetCredidentails(group, merchant, store, token string)

type SecurePayResponse

type SecurePayResponse struct {
	Result   string       `json:"ret_code"`
	RetMsg   string       `json:"ret_msg"`
	Response SecurePayRet `json:"result"`
}

AddResponse is the Response from the Yuansfer service.

type SecurePayRet

type SecurePayRet struct {
	Amount         string `json:"amount"`
	Currency       string `json:"currency"`
	TransactionNo  string `json:"transactionNo"`
	Reference      string `json:"reference"`
	CashierURL     string `json:"cashierUrl"`
	SettleCurrency string `json:"settleCurrency"`
}

AddRet is the Response from the Yuansfer service.

type Yuansfer

type Yuansfer interface {
	PostToYuansfer() ([]byte, error)
}

Yuansfer payment method

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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