paypal

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 11 Imported by: 1

README

PayPal SDK for Golang

已实现接口

PaymentS API
  • Get an access token (获取 Access Token)

    POST /v1/oauth2/token

  • Create a payment (创建账单)

    POST /v1/payments/payment

  • Execute approved PayPal payment (核准账单支付信息)

    POST /v1/payments/payment/#payment_id/execute

  • Show payment details (获取账单详情)

    GET /v1/payments/payment/#payment_id

  • List payments (获取账单列表)

    GET /v1/payments/payment

  • Show sale details (获取交易详情)

    GET /v1/payments/sale/#sale_id

  • Refund sale (发起退款)

    POST /v1/payments/sale/#sale_id/refund

  • Show refund details (获取退款详情)

    GET /v1/payments/refund/#refund_id

Webhooks API
  • Create webhook (创建钩子)

    POST /v1/notifications/webhooks

  • Show webhook details (获取钩子详情)

    POST /v1/notifications/webhooks/#webhook_id

  • List all webhooks (获取所有的钩子)

    GET /v1/notifications/webhooks

  • Delete webhook (删除钩子)

    DELETE /v1/notifications/webhooks/#webhook_id

集成流程

Sandbox 账户

从网页 Sandbox - Accounts 可以创建和查看 Sandbox 环境的用户,这样就可以使用测试环境进行实际的支付和收款操作了。

大家在创建 Sandbox 账户的时候,要注意账户有两种类型,即商户和个人,实际测试的时候,应该创建一个商户账户和一个个人账户,商户账户和 App 进行关联,这样个人账户向 App 支付的时候,款项将转入商户的账户中。

Sandbox 账户有专门测试网站 https://www.sandbox.paypal.com/cn/,该网站提供的功能和网站 https://www.paypal.com/cn/ 提供的功能是一致的,比如收入、支出、退款操作等,只不过里面的数据都是测试数据。

创建 App

访问网站 https://developer.paypal.com/, 使用 PayPal 的账号登录,进入 My Apps & Credentials 页面, 找到 REST API apps,点击 Create App 创建一个新的 App,创建成功之后可以获取到 Client IDSecret,我们后续在进行认证的时候会用到这两个参数。

创建 App 的时候,需要关联一个 Sanbox 环境的商户账户。

获取 Access Token

import "github.com/smartwalle/paypal"

var client = paypal.New("ClientID", "Secret", false) // 第三个参数用于标记是否为生产环境,true 为生产环境,false 为 Sandbox 环境。

var token, err = client.GetAccessToken() // 获取 Access Token

在实际使用过程中,一般不需要单独调用此方法获取 Access Token,除非你有需要。

在访问其它需要认证的接口的时候,组件会自动判断当前是否有正常可用的 Access Token,如果没有,会先向 PayPal 请求 Access Token, 然后再进行业务接口的访问。

创建账单

创建账单提供了两种方式:

1. 快速创建账单
var payment, err = client.ExpressCreatePayment(invoiceNumber, total, currency, cancelURL, returnURL)
...
2. 高级接口
var p = &paypal.Payment{}
p.Intent = paypal.PaymentIntentSale
p.Payer = &paypal.Payer{}
p.Payer.PaymentMethod = "paypal"
p.RedirectURLs = &paypal.RedirectURLs{}
p.RedirectURLs.CancelURL = "http://www.baidu.com"
p.RedirectURLs.ReturnURL = "http://127.0.0.1:9001/paypal"

var transaction = &paypal.Transaction{}
p.Transactions = []*paypal.Transaction{transaction}

transaction.Amount = &paypal.Amount{}
transaction.Amount.Total = "30.11"
transaction.Amount.Currency = "USD"
transaction.Amount.Details = &paypal.AmountDetails{}
transaction.Amount.Details.Subtotal = "30.00"
transaction.Amount.Details.Tax = "0.07"
transaction.Amount.Details.Shipping = "0.03"
transaction.Amount.Details.HandlingFee = "1.00"
transaction.Amount.Details.ShippingDiscount = "-1.00"
transaction.Amount.Details.Insurance = "0.01"

transaction.Description = "This is the payment transaction description."
transaction.Custom = "EBAY_EMS_90048630024435"
transaction.InvoiceNumber = uuid.New() // 随机生成一串 Invoice Number

transaction.PaymentOptions = &paypal.PaymentOptions{}
transaction.PaymentOptions.AllowedPaymentMethod = "INSTANT_FUNDING_SOURCE"
transaction.SoftDescriptor = "ECHI5786786"

transaction.ItemList = &paypal.ItemList{}
transaction.ItemList.ShippingAddress = &paypal.ShippingAddress{}
transaction.ItemList.ShippingAddress.RecipientName = "Hello World"
transaction.ItemList.ShippingAddress.Line1 = "4thFloor"
transaction.ItemList.ShippingAddress.Line2 = "unit#34"
transaction.ItemList.ShippingAddress.City = "SAn Jose"
transaction.ItemList.ShippingAddress.CountryCode = "US"
transaction.ItemList.ShippingAddress.PostalCode = "95131"
transaction.ItemList.ShippingAddress.Phone = "011862212345678"
transaction.ItemList.ShippingAddress.State = "CA"

var i1, i2 = &paypal.Item{}, &paypal.Item{}
transaction.ItemList.Items = []*paypal.Item{i1, i2}

i1.Name = "hat"
i1.Description = "Brown color hat"
i1.Quantity = "5"
i1.Price = "3"
i1.Tax = "0.01"
i1.SKU = "1"
i1.Currency = "USD"

i2.Name = "handbag"
i2.Description = "Black color hand bag"
i2.Quantity = "1"
i2.Price = "15"
i2.Tax = "0.02"
i2.SKU = "product34"
i2.Currency = "USD"

p.NoteToPayer = "Contact us for any questions on your order."

var payment, err = client.CreatePayment(p)
fmt.Println(payment, err)

这种创建账单的方式虽然会比较复杂,但是信息也比较全面,用户在支付的时候,也能够看到详细的商品清单信息,会显得更加的友好。

支付

从创建账单返回的 Payment 信息中,我们会得到一个 Link 类型的数组 payment.Links,该数组一般含有三个数据,我们要取出其中一个 rel 属性的值为 approval_url 的 Link,然后在浏览器里面打开其 href 属性对应的链接地址,这样就可以进行登录并支付了。

OK,PayPal 显示支付成功了,也成功跳转到了我们设置的 ReturnURL,这时候进入商户账户,但是还是没有任何的入账信息,这是为什么呢?

创建账单的时候,Payment 有一个 RedirectURLs 属性,该属性有两个值,一个为 CancelURL,另一个为 ReturnURL。

CancelURL 为用户取消支付跳转的 URL;ReturnURL 为用户支付成功跳转的 URL;

当我们支付成功之后,浏览器将跳转到 ReturnURL,跳转到该 URL 之后,我们还要进行一步工作,这样才能保证支付完成。

核准账单支付信息

支付成功之后,浏览器跳转到 ReturnURL 的时候,附带了几个参数:paymentId、token 和 PayerID。

http://192.168.192.250:3000/paypal?paymentId=PAY-37A82711YL064934DLB4G3AQ&token=EC-0DG12278CE6129333&PayerID=XV9HF9K25FB38

核准账单支付信息的时候,需要用到 paymentId 和 payerID。

我们在提供的 ReturnURL 接口中应执行核准账单支付信息的操作。

var payment, err = client.ExecuteApprovedPayment(paymentId, payerID)
...

如果返回的 payment 的 State 为 “approved”,则表示核准账单支付成功(注意:不能以此来判断是否支付成功,即实际到账)。

如果要判断是否实际到账,需要判断返回结果中的 transactions[xx].related_resources[xx].sale.state 的值,当该字段的值为 completed 的时候,才能说明已到账。

到此,可以算是完成了一个完整的收款流程,如果想要更加严谨,还需要加上 webhook。

总结

一个简单的支付流程:

  1. 初始化 paypal 信息:

    var client = paypal.New(...)
    
  2. 创建账单

    var p = &Payment{}
    ...
    client.CreatePayment(p)
    
  3. 从账单中获取类型为 approval_url 的 URL,浏览器打开进行支付

  4. ReturnURL 接口中进行核准账单支付

    var client = paypal.New(...)
    var p, err = client.ExecuteApprovedPayment(paymentId, payerID)
    ...
    

Webhook (钩子)

待续...

Documentation

Index

Constants

View Source
const (
	ErrTypeValidation         = "VALIDATION_ERROR"
	ErrTypeInstrumentDeclined = "INSTRUMENT_DECLINED"
	ErrTypePaymentAlreadyDone = "PAYMENT_ALREADY_DONE"
)
View Source
const (
	EventTypePaymentSaleCompleted = "PAYMENT.SALE.COMPLETED"
	EventTypePaymentSaleDenied    = "PAYMENT.SALE.DENIED"
	EventTypePaymentSalePending   = "PAYMENT.SALE.PENDING"

	// 退款成功
	EventTypePaymentSaleRefunded = "PAYMENT.SALE.REFUNDED"
	EventTypePaymentSaleReversed = "PAYMENT.SALE.REVERSED"

	// 用户从 paypal 网站申请退款
	EventTypeCustomerDisputeCreated  = "CUSTOMER.DISPUTE.CREATED"
	EventTypeCustomerDisputeResolved = "CUSTOMER.DISPUTE.RESOLVED"
	EventTypeCustomerDisputeUpdated  = "CUSTOMER.DISPUTE.UPDATED"
)

https://developer.paypal.com/docs/integration/direct/webhooks/event-names/

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

Types

type Address

type Address struct {
	Line1       string `json:"line1,omitempty"`
	Line2       string `json:"line2,omitempty"`
	City        string `json:"city,omitempty"`
	State       string `json:"state,omitempty"`
	PostalCode  string `json:"postal_code,omitempty"`
	CountryCode string `json:"country_code,omitempty"`
	Phone       string `json:"phone,omitempty"`
}

type Amount

type Amount struct {
	Total    string         `json:"total,omitempty"`    // required
	Currency string         `json:"currency,omitempty"` // required
	Details  *AmountDetails `json:"details,omitempty"`
}

type AmountDetails

type AmountDetails struct {
	Subtotal         string `json:"subtotal,omitempty"`
	Shipping         string `json:"shipping,omitempty"`
	Tax              string `json:"tax,omitempty"`
	HandlingFee      string `json:"handling_fee,omitempty"`
	ShippingDiscount string `json:"shipping_discount,omitempty"`
	Insurance        string `json:"insurance,omitempty"`
	GiftWrap         string `json:"gift_wrap,omitempty"`
}

type BillingAddress

type BillingAddress struct {
	Line1               string `json:"line1,omitempty"`
	Line2               string `json:"line2,omitempty"`
	City                string `json:"city,omitempty"`
	State               string `json:"state,omitempty"`
	CountryCode         string `json:"country_code,omitempty"`
	PostalCode          string `json:"postal_code,omitempty"`
	Phone               string `json:"phone,omitempty"`
	NormalizationStatus string `json:"normalization_status,omitempty"`
	Status              string `json:"status,omitempty"`
	Type                string `json:"type,omitempty"`
}

type BillingInfo

type BillingInfo struct {
	Email        string   `json:"email,omitempty"`
	Phone        *Phone   `json:"phone,omitempty"`
	BusinessName string   `json:"business_name,omitempty"`
	FirstName    string   `json:"first_name,omitempty"`
	LastName     string   `json:"last_name,omitempty"`
	Address      *Address `json:"address,omitempty"`
	Language     string   `json:"language,omitempty"`
}

type Buyer

type Buyer struct {
	Email string `json:"email,omitempty"`
	Name  string `json:"name,omitempty"`
}

type Client

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

func New

func New(clientId, secret string, isProduction bool) (client *Client)

func (*Client) BuildAPI

func (this *Client) BuildAPI(paths ...string) string

func (*Client) CreatePayment

func (this *Client) CreatePayment(payment *Payment) (result *Payment, err error)

CreatePayment https://developer.paypal.com/docs/api/payments/#payment 因为接口返回的 payment 数据只比提交的 payment 数据多了几个字段,所以本接口的参数和返回结果共用同一数据结构。

func (*Client) CreateWebExperienceProfile

func (this *Client) CreateWebExperienceProfile(param *WebProfiles) (result *WebProfiles, err error)

CreateWebExperienceProfile https://developer.paypal.com/docs/api/payment-experience/#web-profile

func (*Client) CreateWebhook

func (this *Client) CreateWebhook(callBackURL string, eventTypeList ...string) (result *Webhook, err error)

CreateWebhook https://developer.paypal.com/docs/api/webhooks/#webhooks_create

func (*Client) DeleteCreditCard

func (this *Client) DeleteCreditCard(creditCardId string) (err error)

DeleteCreditCard https://developer.paypal.com/docs/api/vault/#credit-cards_delete

func (*Client) DeleteWebExperienceProfile

func (this *Client) DeleteWebExperienceProfile(profileId string) (err error)

DeleteWebExperienceProfile https://developer.paypal.com/docs/api/payment-experience/#web-profiles_delete

func (*Client) DeleteWebhook

func (this *Client) DeleteWebhook(webhookId string) (err error)

DeleteWebhook https://developer.paypal.com/docs/api/webhooks/#webhooks_delete

func (*Client) ExecuteApprovedPayment

func (this *Client) ExecuteApprovedPayment(paymentId, payerId string) (result *Payment, err error)

ExecuteApprovedPayment https://developer.paypal.com/docs/api/payments/#payment_execute 从回调 URL 中获取 PayerId

func (*Client) ExpressCreatePayment

func (this *Client) ExpressCreatePayment(invoiceNumber, total, currency, cancelURL, returnURL string) (result *Payment, err error)

func (*Client) GetAccessToken

func (this *Client) GetAccessToken() (token *Token, err error)

func (*Client) GetCreditCardDetails

func (this *Client) GetCreditCardDetails(creditCardId string) (result *CreditCard, err error)

GetCreditCardDetails https://developer.paypal.com/docs/api/vault/#credit-cards_delete

func (*Client) GetCreditCardList

func (this *Client) GetCreditCardList(param *CreditCardListParam) (result *CreditCardList, err error)

GetCreditCardList https://developer.paypal.com/docs/api/vault/#credit-cards_list

func (*Client) GetDisputeDetails

func (this *Client) GetDisputeDetails(disputeId string) (result *Dispute, err error)

GetDisputeDetails https://developer.paypal.com/docs/api/customer-disputes/#disputes_get-dispute

func (*Client) GetDisputeList

func (this *Client) GetDisputeList(param *DisputeListParam) (result *DisputeList, err error)

GetDisputeList https://developer.paypal.com/docs/api/customer-disputes/#disputes_get-disputes

func (*Client) GetPaymentDetails

func (this *Client) GetPaymentDetails(paymentId string) (result *Payment, err error)

GetPaymentDetails https://developer.paypal.com/docs/api/payments/#payment_get

func (*Client) GetPaymentList

func (this *Client) GetPaymentList(param *PaymentListParam) (result *PaymentList, err error)

GetPaymentList https://developer.paypal.com/docs/api/payments/#payment_list

func (*Client) GetRefundDetails

func (this *Client) GetRefundDetails(refundId string) (result *Refund, err error)

GetRefundDetails https://developer.paypal.com/docs/api/payments/#refund_get

func (*Client) GetSaleDetails

func (this *Client) GetSaleDetails(saleId string) (result *Sale, err error)

GetSaleDetails https://developer.paypal.com/docs/api/payments/#sale_get

func (*Client) GetWebExperienceProfileDetails

func (this *Client) GetWebExperienceProfileDetails(profileId string) (result *WebProfiles, err error)

GetWebExperienceProfileDetails https://developer.paypal.com/docs/api/payment-experience/#web-profiles_get

func (*Client) GetWebExperienceProfileList

func (this *Client) GetWebExperienceProfileList() (result []*WebProfiles, err error)

GetWebExperienceProfileList https://developer.paypal.com/docs/api/payment-experience/#web-profiles_get-list

func (*Client) GetWebhookDetails

func (this *Client) GetWebhookDetails(webhookId string) (result *Webhook, err error)

GetWebhookDetails https://developer.paypal.com/docs/api/webhooks/#webhooks_get

func (*Client) GetWebhookEvent

func (this *Client) GetWebhookEvent(webhookId string, req *http.Request) (event *Event, err error)

GetWebhookEvent 用于处理 webbook 回调

func (*Client) GetWebhookList

func (this *Client) GetWebhookList() (result *WebhookList, err error)

GetWebhookList https://developer.paypal.com/docs/api/webhooks/#webhooks_get-all

func (*Client) RefundSale

func (this *Client) RefundSale(saleId string, param *RefundSaleParam) (result *Refund, err error)

RefundSale https://developer.paypal.com/docs/api/payments/#sale_refund

func (*Client) StoreCreditCard

func (this *Client) StoreCreditCard(param *CreditCard) (result *CreditCard, err error)

StoreCreditCard https://developer.paypal.com/docs/api/vault/#credit-cards_create

func (*Client) UpdateWebExperienceProfiles

func (this *Client) UpdateWebExperienceProfiles(profileId string, param *WebProfiles) (err error)

UpdateWebExperienceProfiles https://developer.paypal.com/docs/api/payment-experience/#web-profiles_update

type Cost

type Cost struct {
	Percent int       `json:"percent,omitempty"`
	Amount  *Currency `json:"amount,omitempty"`
}

type CreditCard

type CreditCard struct {
	// Request body
	Number             string          `json:"number,omitempty"`          // required
	Type               string          `json:"type,omitempty"`            // required
	ExpireMonth        string          `json:"expire_month,omitempty"`    // required
	ExpireYear         string          `json:"expire_year,omitempty"`     // required
	BillingAddress     *BillingAddress `json:"billing_address,omitempty"` // required
	FirstName          string          `json:"first_name,omitempty"`
	LastName           string          `json:"last_name,omitempty"`
	ExternalCustomerId string          `json:"external_customer_id,omitempty"`
	MerchantId         string          `json:"merchant_id,omitempty"`
	PayerId            string          `json:"payer_id,omitempty"`
	ExternalCardId     string          `json:"external_card_id,omitempty"`

	Id         string  `json:"id,omitempty"`
	State      string  `json:"state,omitempty"`
	CreateTime string  `json:"create_time,omitempty"`
	UpdateTime string  `json:"update_time,omitempty"`
	ValidUntil string  `json:"valid_until,omitempty"`
	Links      []*Link `json:"links,omitempty"`
}

type CreditCardList

type CreditCardList struct {
	Items      []*CreditCard `json:"items,omitempty"`
	TotalItems int           `json:"total_items,omitempty"`
	TotalPages int           `json:"total_pages,omitempty"`
	Links      []*Link       `json:"links,omitempty"`
}

type CreditCardListParam

type CreditCardListParam struct {
	PageSize           int
	Page               int
	StartTime          string
	EndTime            string
	SortOrder          string
	SortBy             string
	MerchantId         string
	ExternalCardId     string
	ExternalCustomerId string
	TotalRequired      bool
}

func (*CreditCardListParam) QueryString

func (this *CreditCardListParam) QueryString() string

type CreditCardToken

type CreditCardToken struct {
	CreditCardId string `json:"credit_card_id,omitempty"` // required
	PayerId      string `json:"payer_id,omitempty"`
	Last4        string `json:"last4,omitempty"`
	Type         string `json:"type,omitempty"`
	ExpireMonth  string `json:"expire_month,omitempty"`
	ExpireYear   string `json:"expire_year,omitempty"`
}

type Currency

type Currency struct {
	Currency string `json:"currency,omitempty"`
	Value    string `json:"value,omitempty"`
}

type CustomAmount

type CustomAmount struct {
	Label  string    `json:"label,omitempty"`
	Amount *Currency `json:"amount,omitempty"`
}

type Dispute

type Dispute struct {
	DisputeId             string                 `json:"dispute_id,omitempty"`
	CreateTime            string                 `json:"create_time,omitempty"`
	UpdateTime            string                 `json:"update_time,omitempty"`
	DisputedTransactions  []*DisputedTransaction `json:"disputed_transactions,omitempty"`
	Reason                string                 `json:"reason,omitempty"`
	Status                DisputeStatus          `json:"status,omitempty"`
	DisputeAmount         *Currency              `json:"dispute_amount,omitempty"`
	DisputeOutcome        *DisputeOutcome        `json:"dispute_outcome,omitempty"`
	Messages              []*Message             `json:"messages,omitempty"`
	SellerResponseDueDate string                 `json:"seller_response_due_date,omitempty"`
	Links                 []*Link                `json:"links,omitempty"`
}

type DisputeList

type DisputeList struct {
	Items []*Dispute `json:"items,omitempty"`
	Links []*Link    `json:"links,omitempty"`
}

type DisputeListParam

type DisputeListParam struct {
	StartTime             string
	DisputedTransactionId string
	PageSize              int
	NextPageToken         string
	DisputeState          string
}

func (*DisputeListParam) QueryString

func (this *DisputeListParam) QueryString() string

type DisputeOutcome

type DisputeOutcome struct {
	OutcomeCode    string    `json:"outcome_code,omitempty"`
	AmountRefunded *Currency `json:"amount_refunded,omitempty"`
}

type DisputeStatus

type DisputeStatus string
const (
	DisputeStatusOpen                     DisputeStatus = "OPEN"
	DisputeStatusWaitingForBuyerResponse  DisputeStatus = "WAITING_FOR_BUYER_RESPONSE"
	DisputeStatusWaitingForSellerResponse DisputeStatus = "WAITING_FOR_SELLER_RESPONSE"
	DisputeStatusUnderReview              DisputeStatus = "UNDER_REVIEW"
	DisputeStatusResolved                 DisputeStatus = "RESOLVED"
	DisputeStatusOther                    DisputeStatus = "OTHER"
)

type DisputedTransaction

type DisputedTransaction struct {
	BuyerTransactionId       string                     `json:"buyer_transaction_id,omitempty"`
	SellerTransactionId      string                     `json:"seller_transaction_id,omitempty"`
	CreateTime               string                     `json:"create_time,omitempty"`
	TransactionStatus        string                     `json:"transaction_status,omitempty"`
	GrossAmount              *Currency                  `json:"gross_amount,omitempty"`
	InvoiceNumber            string                     `json:"invoice_number,omitempty"`
	Custom                   string                     `json:"custom,omitempty"`
	Buyer                    *Buyer                     `json:"buyer,omitempty"`
	Seller                   *Seller                    `json:"seller,omitempty"`
	Items                    []*DisputedTransactionItem `json:"items,omitempty"`
	SellerProtectionEligible bool                       `json:"seller_protection_eligible,omitempty"`
}

type DisputedTransactionItem

type DisputedTransactionItem struct {
	ItemId               string    `json:"item_id,omitempty"`
	PartnerTransactionId string    `json:"partner_transaction_id,omitempty"`
	Reason               string    `json:"reason,omitempty"`
	DisputeAmount        *Currency `json:"dispute_amount,omitempty"`
	Notes                string    `json:"notes,omitempty"`
}

type ErrorDetail

type ErrorDetail struct {
	Field string `json:"field"`
	Issue string `json:"issue"`
}

type Event

type Event struct {
	Id           string       `json:"id"`
	CreateTime   string       `json:"create_time,omitempty"`
	ResourceType ResourceType `json:"resource_type,omitempty"`
	EventVersion string       `json:"event_version,omitempty"`
	EventType    string       `json:"event_type,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	Resource     interface{}  `json:"resource,omitempty"`
	Status       string       `json:"status,omitempty"`
	Links        []*Link      `json:"links,omitempty"`
}

func (*Event) Dispute

func (this *Event) Dispute() *Dispute

func (*Event) Invoice

func (this *Event) Invoice() *Invoice

func (*Event) Refund

func (this *Event) Refund() *Refund

func (*Event) Sale

func (this *Event) Sale() *Sale

type EventType

type EventType struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status,omitempty"`
}

type FMFDetails

type FMFDetails struct {
	FilterType  string `json:"filter_type,omitempty"`
	FilterId    string `json:"filter_id,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
}

type FileAttachment

type FileAttachment struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

type FundingInstrument

type FundingInstrument struct {
	CreditCard      *CreditCard      `json:"credit_card,omitempty"`
	CreditCardToken *CreditCardToken `json:"credit_card_token,omitempty"`
}

type IdentityError

type IdentityError struct {
	Response         *http.Response `json:"-"`
	Name             string         `json:"error"`
	ErrorDescription string         `json:"error_description"`
}

func (*IdentityError) Error

func (this *IdentityError) Error() string

type Invoice

type Invoice struct {
	Id                         string            `json:"id,omitempty"`
	Number                     string            `json:"number,omitempty"`
	URI                        string            `json:"uri,omitempty"`
	Status                     string            `json:"status,omitempty"`
	TemplateId                 string            `json:"template_id,omitempty"`
	MerchantInfo               *MerchantInfo     `json:"merchant_info,omitempty"`
	BillingInfo                []*BillingInfo    `json:"billing_info,omitempty"`
	ShippingInfo               *ShippingInfo     `json:"shipping_info,omitempty"`
	CCInfo                     *Participant      `json:"cc_info,omitempty"`
	Items                      []*InvoiceItem    `json:"items,omitempty"`
	InvoiceDate                string            `json:"invoice_date,omitempty"`
	PaymentTerm                *PaymentTerm      `json:"payment_term,omitempty"`
	Reference                  string            `json:"reference,omitempty"`
	Discount                   *Cost             `json:"discount,omitempty"`
	ShippingCost               *ShippingCost     `json:"shipping_cost,omitempty"`
	Custom                     *CustomAmount     `json:"custom,omitempty"`
	AllowPartialPayment        bool              `json:"allow_partial_payment,omitempty"`
	MinimumAmountDue           *Currency         `json:"minimum_amount_due,omitempty"`
	TaxCalculatedAfterDiscount bool              `json:"tax_calculated_after_discount,omitempty"`
	TaxInclusive               bool              `json:"tax_inclusive,omitempty"`
	Terms                      string            `json:"terms,omitempty"`
	Note                       string            `json:"note,omitempty"`
	MerchantMemo               string            `json:"merchant_memo,omitempty"`
	LogoURL                    string            `json:"logo_url,omitempty"`
	TotalAmount                *Currency         `json:"total_amount,omitempty"`
	Payments                   []*PaymentDetail  `json:"payments,omitempty"`
	Refunds                    []*RefundDetail   `json:"refunds,omitempty"`
	Metadata                   *Metadata         `json:"metadata,omitempty"`
	PaidAmount                 *PaymentSummary   `json:"paid_amount,omitempty"`
	RefundedAmount             *PaymentSummary   `json:"refunded_amount,omitempty"`
	Attachments                []*FileAttachment `json:"attachments,omitempty"`
	AllowTip                   bool              `json:"allow_tip,omitempty"`
	Links                      []*Link           `json:"links,omitempty"`
}

type InvoiceItem

type InvoiceItem struct {
	Name          string    `json:"name,omitempty"`
	Description   string    `json:"description,omitempty"`
	Quantity      int       `json:"quantity,omitempty"`
	UnitPrice     *Currency `json:"unit_price,omitempty"`
	Tax           *Tax      `json:"tax,omitempty"`
	Date          string    `json:"date,omitempty"`
	Discount      *Cost     `json:"discount,omitempty"`
	UnitOfMeasure string    `json:"unit_of_measure,omitempty"`
}

type Item

type Item struct {
	Name        string      `json:"name,omitempty"`
	Description string      `json:"description,omitempty"`
	Quantity    interface{} `json:"quantity,omitempty"` // string or int
	Price       string      `json:"price,omitempty"`
	Tax         string      `json:"tax,omitempty"`
	SKU         string      `json:"sku,omitempty"`
	Currency    string      `json:"currency,omitempty"`
}

type ItemList

type ItemList struct {
	Items               []*Item          `json:"items,omitempty"`
	ShippingAddress     *ShippingAddress `json:"shipping_address,omitempty"`
	ShippingMethod      string           `json:"shipping_method,omitempty"`
	ShippingPhoneNumber string           `json:"shipping_phone_number,omitempty"`
}
type Link struct {
	Href    string `json:"href,omitempty"`
	Rel     string `json:"rel,omitempty"`
	Method  string `json:"method,omitempty"`
	EncType string `json:"encType,omitempty"`
}

type Logger

type Logger interface {
	SetPrefix(prefix string)
	Prefix() string
	Println(args ...interface{})
	Printf(format string, args ...interface{})
	Output(calldepth int, s string) error
}

type MerchantInfo

type MerchantInfo struct {
	Email          string   `json:"email,omitempty"`
	BusinessName   string   `json:"business_name,omitempty"`
	FirstName      string   `json:"first_name,omitempty"`
	LastName       string   `json:"last_name,omitempty"`
	Phone          *Phone   `json:"phone,omitempty"`
	Fax            *Phone   `json:"fax,omitempty"`
	Address        *Address `json:"address,omitempty"`
	Website        string   `json:"website,omitempty"`
	TaxId          string   `json:"tax_id,omitempty"`
	AdditionalInfo string   `json:"additional_info,omitempty"`
}

type Message

type Message struct {
	PostedBy   string `json:"posted_by,omitempty"`
	TimePosted string `json:"time_posted,omitempty"`
	Content    string `json:"content,omitempty"`
}

type Metadata

type Metadata struct {
	CreatedDate     string `json:"created_date,omitempty"`
	CreatedBy       string `json:"created_by,omitempty"`
	CancelledDate   string `json:"cancelled_date,omitempty"`
	CancelledBy     string `json:"cancelled_by,omitempty"`
	LastUpdatedDate string `json:"last_updated_date,omitempty"`
	LastUpdatedBy   string `json:"last_updated_by,omitempty"`
	FirstSentDate   string `json:"first_sent_date,omitempty"`
	LastSentDate    string `json:"last_sent_date,omitempty"`
	LastSentBy      string `json:"last_sent_by,omitempty"`
	PayerViewURL    string `json:"payer_view_url,omitempty"`
}

type Participant

type Participant struct {
	Email string `json:"email,omitempty"`
}

type Payee

type Payee struct {
	MerchantID string `json:"merchant_id,omitempty"`
	Email      string `json:"email,omitempty"`
}

type Payer

type Payer struct {
	PaymentMethod     PaymentMethod      `json:"payment_method,omitempty"`
	Status            string             `json:"status,omitempty"`
	PayerInfo         *PayerInfo         `json:"payer_info,omitempty"`
	FundingInstrument *FundingInstrument `json:"funding_instrument,omitempty"`
}

type PayerInfo

type PayerInfo struct {
	Email           string           `json:"email,omitempty"`
	Salutation      string           `json:"salutation,omitempty"`
	FirstName       string           `json:"first_name,omitempty"`
	MiddleName      string           `json:"middle_name,omitempty"`
	LastName        string           `json:"last_name,omitempty"`
	Suffix          string           `json:"suffix,omitempty"`
	PayerId         string           `json:"payer_id,omitempty"`
	Phone           string           `json:"phone,omitempty"`
	PhoneType       string           `json:"phone_type,omitempty"`
	BirthDate       string           `json:"birth_date,omitempty"`
	TaxId           string           `json:"tax_id,omitempty"`
	TaxIdType       string           `json:"tax_id_type,omitempty"`
	CountryCode     string           `json:"country_code,omitempty"`
	BillingAddress  *BillingAddress  `json:"billing_address,omitempty"`
	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
}

type Payment

type Payment struct {
	// Request body
	Intent              PaymentIntent  `json:"intent,omitempty"`       // required
	Payer               *Payer         `json:"payer,omitempty"`        // required
	Transactions        []*Transaction `json:"transactions,omitempty"` // required
	ExperienceProfileId string         `json:"experience_profile_id,omitempty"`
	NoteToPayer         string         `json:"note_to_payer,omitempty"`
	RedirectURLs        *RedirectURLs  `json:"redirect_urls"`

	// 返回结果添加的字段
	Id            string       `json:"id,omitempty"`
	CreateTime    string       `json:"create_time,omitempty"`
	State         PaymentState `json:"state,omitempty"`
	FailureReason string       `json:"failure_reason,omitempty"`
	UpdateTime    string       `json:"update_time,omitempty"`
	Links         []*Link      `json:"links,omitempty"`
}

type PaymentDetail

type PaymentDetail struct {
	Type            string    `json:"type,omitempty"`
	TransactionId   string    `json:"transaction_id,omitempty"`
	TransactionType string    `json:"transaction_type,omitempty"`
	Date            string    `json:"date,omitempty"`
	Method          string    `json:"method,omitempty"`
	Note            string    `json:"note,omitempty"`
	Amount          *Currency `json:"amount,omitempty"`
}

type PaymentHoldReason

type PaymentHoldReason struct {
	PaymentHoldReason string `json:"payment_hold_reason,omitempty"`
}

type PaymentIntent

type PaymentIntent string
const (
	PaymentIntentSale      PaymentIntent = "sale"
	PaymentIntentAuthorize PaymentIntent = "authorize"
	PaymentIntentOrder     PaymentIntent = "order"
)

type PaymentList

type PaymentList struct {
	Payments []*Payment `json:"payments,omitempty"`
	Count    int        `json:"count,omitempty"`
	NextId   string     `json:"next_id,omitempty"`
}

type PaymentListParam

type PaymentListParam struct {
	Count      int
	StartId    string
	StartIndex int
	StartTime  string
	EndTime    string
	SortBy     string
	SortOrder  string
}

func (*PaymentListParam) QueryString

func (this *PaymentListParam) QueryString() string

type PaymentMethod

type PaymentMethod string
const (
	PaymentMethodPayPal     PaymentMethod = "paypal"
	PaymentMethodCreditCard PaymentMethod = "credit_card"
)

type PaymentOptions

type PaymentOptions struct {
	AllowedPaymentMethod string `json:"allowed_payment_method,omitempty"`
}

type PaymentState

type PaymentState string
const (
	PaymentStateCreated  PaymentState = "created"
	PaymentStateApproved PaymentState = "approved"
	PaymentStateFailed   PaymentState = "failed"
)

type PaymentSummary

type PaymentSummary struct {
	Paypal *Currency `json:"paypal,omitempty"`
	Other  *Currency `json:"other,omitempty"`
}

type PaymentTerm

type PaymentTerm struct {
	TermType string `json:"term_type,omitempty"`
	DueDate  string `json:"due_date,omitempty"`
}

type Phone

type Phone struct {
	CountryCode    string `json:"country_code,omitempty"`
	NationalNumber string `json:"national_number,omitempty"`
}

type ProcessorResponse

type ProcessorResponse struct {
	ResponseCode string `json:"response_code,omitempty"`
	AVSCode      string `json:"avs_code,omitempty"`
	CVVCode      string `json:"cvv_code,omitempty"`
	AdviceCode   string `json:"advice_code,omitempty"`
	ECISubmitted string `json:"eci_submitted,omitempty"`
	Vpas         string `json:"vpas,omitempty"`
}

type RedirectURLs

type RedirectURLs struct {
	ReturnURL string `json:"return_url,omitempty"`
	CancelURL string `json:"cancel_url,omitempty"`
}

type Refund

type Refund struct {
	Id               string      `json:"id,omitempty"`
	Amount           *Amount     `json:"amount,omitempty"`
	State            RefundState `json:"state,omitempty"`
	Reason           string      `json:"reason,omitempty"`
	RefundReasonCode string      `json:"refund_reason_code,omitempty"`
	InvoiceNumber    string      `json:"invoice_number,omitempty"`
	SaleId           string      `json:"sale_id,omitempty"`
	CaptureId        string      `json:"capture_id,omitempty"`
	ParentPayment    string      `json:"parent_payment,omitempty"`
	Description      string      `json:"description,omitempty"`
	CreateTime       string      `json:"create_time,omitempty"`
	UpdateTime       string      `json:"update_time,omitempty"`
	Custom           string      `json:"custom,omitempty"`
	RefundToPayer    *Currency   `json:"refund_to_payer,omitempty"`
	Links            []*Link     `json:"links,omitempty,omitempty"`
}

type RefundDetail

type RefundDetail struct {
	Type          string    `json:"type,omitempty"`
	TransactionId string    `json:"transaction_id,omitempty"`
	Date          string    `json:"date,omitempty"`
	Note          string    `json:"note,omitempty"`
	Amount        *Currency `json:"amount,omitempty"`
}

type RefundSaleParam

type RefundSaleParam struct {
	Amount        *Amount `json:"amount,omitempty"`
	Description   string  `json:"description,omitempty"`
	Reason        string  `json:"reason,omitempty"`
	InvoiceNumber string  `json:"invoice_number,omitempty"`
}

type RefundState

type RefundState string
const (
	RefundStatePending   RefundState = "pending"
	RefundStateCompleted RefundState = "completed"
	RefundStateCancelled RefundState = "cancelled"
	RefundStateFailed    RefundState = "failed"
)

type RelatedResources

type RelatedResources struct {
	Sale   *Sale   `json:"sale,omitempty"`
	Refund *Refund `json:"refund,omitempty"`
}

type ResourceType

type ResourceType string
const (
	EventResourceTypeInvoices ResourceType = "invoices"
	EventResourceTypeSale     ResourceType = "sale"
	EventResourceTypeRefund   ResourceType = "refund"
	EventResourceTypeDispute  ResourceType = "dispute"
)

type ResponseError

type ResponseError struct {
	Response        *http.Response `json:"-"`
	Name            string         `json:"name"`
	Message         string         `json:"message"`
	InformationLink string         `json:"information_link"`
	DebugId         string         `json:"debug_id"`
	Details         []ErrorDetail  `json:"details"`
}

func (*ResponseError) Error

func (this *ResponseError) Error() string

type Sale

type Sale struct {
	Id                        string              `json:"id,omitempty"`
	PurchaseUnitReferenceId   string              `json:"purchase_unit_reference_id,omitempty"`
	Amount                    *Amount             `json:"amount,omitempty"`
	PaymentMode               string              `json:"payment_mode,omitempty"`
	State                     SaleState           `json:"state,omitempty"`
	ReasonCode                string              `json:"reason_code,omitempty"`
	ProtectionEligibility     string              `json:"protection_eligibility,omitempty"`
	ProtectionEligibilityType string              `json:"protection_eligibility_type,omitempty"`
	ClearingTime              string              `json:"clearing_time,omitempty"`
	PaymentHoldStatus         string              `json:"payment_hold_status,omitempty"`
	PaymentHoldReasons        []PaymentHoldReason `json:"payment_hold_reasons,omitempty"`
	TransactionFee            *Currency           `json:"transaction_fee,omitempty"`
	ReceivableAmount          *Currency           `json:"receivable_amount,omitempty"`
	ExchangeRate              string              `json:"exchange_rate,omitempty"`
	FMFDetails                *FMFDetails         `json:"fmf_details,omitempty"`
	ReceiptId                 string              `json:"receipt_id,omitempty"`
	ParentPayment             string              `json:"parent_payment,omitempty"`
	ProcessorResponse         *ProcessorResponse  `json:"processor_response,omitempty"`
	BillingAgreementId        string              `json:"billing_agreement_id,omitempty"`
	CreateTime                string              `json:"create_time,omitempty"`
	UpdateTime                string              `json:"update_time,omitempty"`
	Links                     []*Link             `json:"links,omitempty,omitempty"`
	InvoiceNumber             string              `json:"invoice_number,omitempty"`
	Custom                    string              `json:"custom,omitempty"`
	SoftDescriptor            string              `json:"soft_descriptor,omitempty"`
}

type SaleState

type SaleState string
const (
	SaleStateCompleted         SaleState = "completed"
	SaleStatePartiallyRefunded SaleState = "partially_refunded"
	SaleStatePending           SaleState = "pending"
	SaleStateRefunded          SaleState = "refunded"
	SaleStateDenied            SaleState = "denied"
)

type Seller

type Seller struct {
	Email      string `json:"email,omitempty"`
	Name       string `json:"name,omitempty"`
	MerchantId string `json:"merchant_id,omitempty"`
}

type ShippingAddress

type ShippingAddress struct {
	RecipientName string `json:"recipient_name,omitempty"`
	Line1         string `json:"line1,omitempty"`
	Line2         string `json:"line2,omitempty"`
	City          string `json:"city,omitempty"`
	CountryCode   string `json:"country_code,omitempty"`
	PostalCode    string `json:"postal_code,omitempty"`
	Phone         string `json:"phone,omitempty"`
	State         string `json:"state,omitempty"`
}

type ShippingCost

type ShippingCost struct {
	Amount *Currency `json:"amount,omitempty"`
	Tax    *Tax      `json:"tax,omitempty"`
}

type ShippingInfo

type ShippingInfo struct {
	FirstName    string   `json:"first_name,omitempty"`
	LastName     string   `json:"last_name,omitempty"`
	BusinessName string   `json:"business_name,omitempty"`
	Address      *Address `json:"address,omitempty"`
}

type Tax

type Tax struct {
	Name    string    `json:"name,omitempty"`
	Percent int       `json:"percent,omitempty"`
	Amount  *Currency `json:"amount,omitempty"`
}

type Token

type Token struct {
	Scope       string    `json:"scope"`
	Nonce       string    `json:"nonce"`
	AccessToken string    `json:"access_token"`
	TokenType   string    `json:"token_type"`
	AppId       string    `json:"app_id"`
	ExpiresIn   int       `json:"expires_in"`
	ExpiresAt   time.Time `json:"expires_at"`
}

type Transaction

type Transaction struct {
	ReferenceId    string          `json:"reference_id,omitempty"`
	Amount         *Amount         `json:"amount,omitempty"` // required
	Payee          *Payee          `json:"payee,omitempty"`
	Description    string          `json:"description,omitempty"`
	NoteToPayee    string          `json:"note_to_payee,omitempty"`
	Custom         string          `json:"custom,omitempty"`
	InvoiceNumber  string          `json:"invoice_number,omitempty"`
	PurchaseOrder  string          `json:"purchase_order,omitempty"`
	SoftDescriptor string          `json:"soft_descriptor,omitempty"`
	PaymentOptions *PaymentOptions `json:"payment_options,omitempty"`
	ItemList       *ItemList       `json:"item_list,omitempty"`
	NotifyURL      string          `json:"notify_url,omitempty"`
	OrderURL       string          `json:"order_url,omitempty"`
	// 返回结果添加的字段
	RelatedResources []*RelatedResources `json:"related_resources,omitempty"`
}

type WebProfiles

type WebProfiles struct {
	// Request body
	Name         string                   `json:"name,omitempty"` // required
	Temporary    bool                     `json:"temporary,omitempty"`
	Presentation *WebProfilesPresentation `json:"presentation,omitempty"`
	InputFields  *WebProfilesInputFields  `json:"input_fields,omitempty"`
	FlowConfig   *WebProfilesFlowConfig   `json:"flow_config,omitempty"`

	Id string `json:"id,omitempty"`
}

type WebProfilesFlowConfig

type WebProfilesFlowConfig struct {
	LandingPageType     string `json:"landing_page_type,omitempty"`
	BankTxnPendingURL   string `json:"bank_txn_pending_url,omitempty"`
	UserAction          string `json:"user_action,omitempty"`
	ReturnURIHttpMethod string `json:"return_uri_http_method,omitempty"`
}

type WebProfilesInputFields

type WebProfilesInputFields struct {
	NoShipping      int `json:"no_shipping,omitempty"`
	AddressOverride int `json:"address_override,omitempty"`
}

type WebProfilesPresentation

type WebProfilesPresentation struct {
	BrandName  string `json:"brand_name,omitempty"`
	LogoImage  string `json:"logo_image,omitempty"`
	LocaleCode string `json:"locale_code,omitempty"`
}

type Webhook

type Webhook struct {
	Id         string       `json:"id,omitempty"`
	URL        string       `json:"url"`
	EventTypes []*EventType `json:"event_types,omitempty"`
	Links      []*Link      `json:"links,omitempty"`
}

type WebhookList

type WebhookList struct {
	Webhooks []*Webhook `json:"webhooks,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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