alipayslim

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 20 Imported by: 0

README

alipayslim

Usage

client := alipayslim.NewClient("2088************")
  WithMD5Key("********************************").
  MustWithRSAKey("-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n").
  WithDebug(false)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
resp, err := configs.DefaultAlipay.SingleTradeQuery(ctx, "MyTradeNo")

params := client.AlipayHKAppPayParams().
  WithBody(paymentTitle).
  WithSubject(paymentTitle).
  WithTotalFee(paymentAmount.String()).
  WithNotifyUrl("https://hippolaundry.com/app").
  WithReferUrl("https://hippolaundry.com/app").
  WithOutTradeNo(tradeNo)
str, err := params.OrderString()

Documentation

Overview

Package alipayslim is a slim version of the Alipay API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the client for the Alipay API.

func NewClient

func NewClient(appId string) *Client

NewClient creates a new client.

func (*Client) AlipayHKAppPayParams

func (c *Client) AlipayHKAppPayParams() *PayParams

AlipayHKAppPayParams returns a new basic parameters for the AlipayHK app pay.

func (*Client) MustWithRSAKey

func (c *Client) MustWithRSAKey(key string) *Client

MustWithRSAKey is like WithRSAKey but panics if the key is invalid.

func (*Client) SingleTradeQuery

func (c *Client) SingleTradeQuery(ctx context.Context, tradeNo string) (*TradeQuery, error)

Call this interface to obtain the information of a particular transaction, such as the transaction ID, out_trade_no, and transaction status. https://global.alipay.com/docs/ac/hkapi/single_trade_query

func (*Client) WithDebug

func (c *Client) WithDebug(debug bool) *Client

WithDebug sets the debug mode and returns the client.

func (*Client) WithMD5Key

func (c *Client) WithMD5Key(key string) *Client

WithMD5Key sets the MD5 key and returns the client.

func (*Client) WithRSAKey

func (c *Client) WithRSAKey(key string) (*Client, error)

WithRSAKey sets the RSA key and returns the client and an error if the key is invalid.

type PayParams

type PayParams struct {
	Data map[string]string
	// contains filtered or unexported fields
}

PayParams is the parameters for the Alipay pay.

func (*PayParams) OrderString

func (p *PayParams) OrderString() (string, error)

OrderString returns the order string for the Alipay HK app pay.

func (*PayParams) WithBody

func (p *PayParams) WithBody(body string) *PayParams

WithBody sets the body and returns the PayParams.

func (*PayParams) WithNotifyUrl

func (p *PayParams) WithNotifyUrl(notifyUrl string) *PayParams

WithNotifyUrl sets the notify URL and returns the PayParams.

func (*PayParams) WithOutTradeNo

func (p *PayParams) WithOutTradeNo(tradeNo string) *PayParams

WithOutTradeNo sets the out trade no and returns the PayParams.

func (*PayParams) WithReferUrl

func (p *PayParams) WithReferUrl(referUrl string) *PayParams

WithReferUrl sets the refer URL and returns the PayParams.

func (*PayParams) WithSubject

func (p *PayParams) WithSubject(subject string) *PayParams

WithSubject sets the subject and returns the PayParams.

func (*PayParams) WithTotalFee

func (p *PayParams) WithTotalFee(totalFee string) *PayParams

WithTotalFee sets the total fee and returns the PayParams.

type Time

type Time struct {
	time.Time
}

Time is the time in UTC+8.

func (Time) MarshalXML

func (t Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML is the method to marshal the time to XML.

func (*Time) UnmarshalXML

func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML is the method to unmarshal the time from XML.

type TradeQuery

type TradeQuery struct {
	// Detailed description about the goods. Special characters are not supported.
	Body string `xml:"body"`

	// Buyer’s Alipay account.
	BuyerEmail string `xml:"buyer_email"`

	// The unique buyer ID assigned by Alipay.
	BuyerID string `xml:"buyer_id"`

	// The discount amount.
	Discount string `xml:"discount"`

	// Indicates whether the trade transaction is locked. If the value is 1, the transaction is locked. If the value is 0, the transaction is not locked.
	FlagTradeLocked string `xml:"flag_trade_locked"`

	// The time when the transaction is created. Format: yyyy-MM-dd HH:mm:ss. Use GMT+8.
	GmtCreate Time `xml:"gmt_create"`

	// The last time when the value of total_fee is modified. Format: yyyy-MM-dd HH:mm:ss. Use GMT +8.
	GmtLastModifiedTime Time `xml:"gmt_last_modified_time"`

	// The time when the transaction is paid by the buyer. Format: yyyy-MM-dd HH:mm:ss. Use GMT+8.
	GmtPayment Time `xml:"gmt_payment"`

	// Indicates whether the total fee is adjusted. The value is T for the adjusted total fee and F for the non-adjusted total fee.
	IsTotalFeeAdjust string `xml:"is_total_fee_adjust"`

	// The operator role, with a value of B for buyers or S for sellers.
	OperatorRole string `xml:"operator_role"`

	// The unique transaction ID that is assigned by the partner.
	OutTradeNo string `xml:"out_trade_no"`

	// The payment type.
	PaymentType string `xml:"payment_type"`

	// Goods prices, which is accurate to 2 digits after the decimal point. The unit is RMB and the value is in the range 0.01 - 100000000.00. The unit is HKD when the buyer paid by Alipay HK.
	Price string `xml:"price"`

	// The quantity of goods.
	Quantity string `xml:"quantity"`

	// Partner Alipay account.
	SellerEmail string `xml:"seller_email"`

	// A unique seller ID assigned by Alipay. This 16-digit number begins with 2088.
	SellerID string `xml:"seller_id"`

	// Brief description of the transaction. Special characters are not supported. Note: The value of this field will be displayed to customers.
	Subject string `xml:"subject"`

	// The accumulative refunded amount paid to the buyer.
	ToBuyerFee string `xml:"to_buyer_fee"`

	// The accumulative amount paid to the seller.
	ToSellerFee string `xml:"to_seller_fee"`

	// The transaction amount in CNY. It is the exact amount that the buyer has paid. Accurate to two decimal places. The transaction amount is in HKD when the buyer paid by Alipay HK.
	TotalFee string `xml:"total_fee"`

	// The unique transaction ID assigned by Alipay, with a length in the range 16 - 64 bits. If out_trade_no and trade_no appear at the same time, trade_no takes precedence.
	TradeNo string `xml:"trade_no"`

	// TradeStatus is used to describe the status of an Online Payment transaction in the specific interfaces. Possible values are:
	// WAIT_BUYER_PAY: The transaction is created and is waiting for the customer to pay.
	// TRADE_FINISHED: The transaction is paid. This status persists even if partial refunds or full refunds occur, or when the refund period is expired.
	// TRADE_CLOSED: The transaction is closed because of payment timeout.
	TradeStatus string `xml:"trade_status"`

	// Indicates whether the Alipay coupon is used in the transaction. The value can be T for a used coupon and F a coupon that is not used.
	UseCoupon string `xml:"use_coupon"`
}

TradeQuery is the response of SingleTradeQuery.

func (TradeQuery) IsPaid

func (t TradeQuery) IsPaid() bool

Return true if the transaction is paid.

Jump to

Keyboard shortcuts

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