paypal

package
v0.0.0-...-85b3fc2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

Quick Start

We have integrated basic settings in NewClient function, you can create a Paypal client easily.

package main

import (
	"context"
	"github.com/Bishoptylaor/paypay/paypal"
	"github.com/Bishoptylaor/paypay/pkg/xlog"
)

var (
	ctx    context.Context
	client *paypal.Client
)

func init() {
	var err error
	ctx = context.Background()
	client, err = paypal.NewClient(ctx,
		paypal.ClientID("Your ClientId"),
		paypal.Secret("Your ClientSecret"),
	)
	if err != nil {
		xlog.Error(err)
		return
	}
}

Settings

You can also use settings for client like ↓ and use your custom setting options.

package main

import (
	"context"
	"github.com/Bishoptylaor/paypay/paypal"
	"github.com/Bishoptylaor/paypay/pkg/xlog"
	"github.com/Bishoptylaor/paypay/pkg/xnet/xhttp"
)

var (
	ctx    context.Context
	client *paypal.Client
)

func init() {
	var err error
	ctx = context.Background()
	client, err = paypal.NewClient(ctx)
	if err != nil {
		xlog.Error(err)
		return
	}

	// set client id and secret
	// 设置账户 ID 和 密钥
	client.Use(paypal.ClientID(""))
	client.Use(paypal.Secret(""))
	// debug flag
	client.Use(paypal.Debug(true))

	// chaining 
	client.
		// use custom headers
		// 自定义 Headers
		Use(paypal.Headers(map[string]string{})).
		// use custom logger
		// 自定义 Logger
		// built-in xlog.Logger
		Use(paypal.SetLogger(xlog.NewLogger())).
		// change prod flag
		// 修改客户端访问环境
		Use(paypal.Prod(false))

	// use multiple settings
	client.Use(
		// use your http client configs
		// 使用你自己的 http client 配置
		paypal.HClient(
			xhttp.NewHttpClientWrapper(&http.Client{
				Timeout: time.Minute,
			}),
		),
		// set params checker before make requests to Paypal
		// 在调用接口前增加参数校验,一般不在 client 初始化阶段使用
		// 规则语法参考 
		paypal.Checker(
			paypay.InjectRuler(map[string][]paypay.Ruler{
				"uri path to your function": []paypay.Ruler{
					paypay.NewRuler("field", `field != nil`, "field in payload cannot be nil"),
				},
			}),
		),
	)
}

Dynamic request to Paypal

Usage

custom request

import (
	"context"
	"github.com/Bishoptylaor/paypay"
	"github.com/Bishoptylaor/paypay/paypal"
	"github.com/Bishoptylaor/paypay/paypal/consts"
	"github.com/Bishoptylaor/paypay/paypal/entity"
	"github.com/Bishoptylaor/paypay/pkg/xlog"
)

func ListProducts(ctx context.Context, client *paypal.Client) {
	query := make(paypay.Payload)
	query.Set("page_size", "10").
		Set("page", "1"). // starts from 1
		Set("total_required", "true")

	emptyRes := entity.EmptyRes{Code: consts.Success}
	res := &entity.ListProductsRes{EmptyRes: emptyRes}
	res.Response = new(entity.ProductList)
	err := client.CustomCallOnce(ctx,
		paypal.ListProducts,
		func() map[string]string {
			return map[string]string{}
		},
		nil,
		query,
		nil,
		emptyRes,
		res.Response,
		paypal.Headers(map[string]string{
			"Prefer": "return=representation",
		}),
		// if you need a call with new Paypal Account , you can use like this ↓
		// paypal.NewToken(ctx, "new client id", "new client secret"),
	)
	if err != nil {
		xlog.Error(err)
		return
	}

	if res.Code != consts.Success {
		xlog.Infof(ctx, "res.Code: %+v", res.Code)
		xlog.Infof(ctx, "res.Error: %+v", res.Error)
		xlog.Infof(ctx, "res.ErrorResponse: %+v", res.ErrorResponse)
		return
	}
	for _, product := range res.Response.Products {
		xlog.Infof(ctx, "product: %+v", product)
	}

	for _, v := range res.Response.Links {
		xlog.Infof(ctx, "res.Response.Links: %+v", v)
	}

}

another example

// any field in your config or db
func customSettings(field1, field2 any) paypal.Settings {
	return func(c *paypal.Client) {
		// set you own info on any field exported
		c.ClientID = "your client id"
		c.ClientSecret = "your client secret"
		c.Prod = false
		// etc.
	}
}

func initCustom() {
	var err error
	client, err = paypal.NewClient(ctx, customSettings())
	if err != nil {
		xlog.Error(err)
	}

	emptyRes := entity.EmptyRes{}

	err = client.CustomCallOnce(
		context.Background(),
		paypal.EmptyMethod,
		func() map[string]string { return map[string]string{} },
		nil,
		nil,
		nil,
		emptyRes,
		nil,
		customSettings(),
	)
}

Hooks

We provide hooks which run before request started, and after response received, so you can do something like inject context, tracing's span etc. it is just similar to web middleware. Here is a default usage, and we`ve implanted it to Client, help you have a concept.


// PPReqPrefix 闭包注入 logger 和 debug 信息
func PPReqPrefix(debug bool, log xlog.XLogger) xhttp.ReqPrefixFunc {
	return func(ctx context.Context, req *http.Request) context.Context {
		if debug == pkg.DebugOn {
			log.Debugf("PayPal_Url: %s", req.URL)
			log.Debugf("PayPal_Req_Body: %s", req.Body)
			log.Debugf("PayPal_Req_Headers: %#v", req.Header)
		} else {
			body, err := io.ReadAll(req.Body)
			if err != nil {
				log.Errorf("[Read Req body] error: %s", err.Error())
				return ctx
			}
			enEscapeUrl, err := url.QueryUnescape(string(body))
			if err == nil {
				log.Infof("[Req] %s", enEscapeUrl)
			}
			req.Body = io.NopCloser(bytes.NewBuffer(body))
		}
		return ctx
	}
}

// PPResSuffix 闭包注入 logger 和 debug 信息
func PPResSuffix(debug bool, log xlog.XLogger) xhttp.ResSuffixFunc {
	return func(ctx context.Context, res *http.Response) context.Context {
		if debug == pkg.DebugOn {
			log.Debugf("PayPal_Response: %d > %s", res.StatusCode, res.Body)
			log.Debugf("PayPal_Rsp_Headers: %#v", res.Header)
		} else {
			body, err := io.ReadAll(res.Body)
			if err != nil {
				log.Errorf("[Read Res body] error: %s", err.Error())
				return ctx
			}
			res.Body = io.NopCloser(bytes.NewBuffer(body))
			log.Infof("[Res] %s", string(body))
		}
		return ctx
	}
}

If former function not suitable for your project, you can use PrefixFunc and SuffixFunc from settings.go to build your own.

You can pass suppress field true to overwrite default functions

Here`s an example of usage.

func DefaultSuffixFunc() Settings {
    return func(client *Client) {
        SuffixFunc(true, PPResSuffix(client.debug, client.Logger))
    }
}

func DefaultPrefixFunc() Settings {
	return func(client *Client) {
		PrefixFunc(true, PPReqPrefix(client.debug, client.Logger))
	}
}

Following functions of Paypal are Supported

Catalog Products

Disputes

Invoicing

Orders

Payments

Payouts

Subscriptions

Transaction Search

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntegrityCheck

func IntegrityCheck(ctx context.Context, c *Client, method string) paypay.ExecuteElem

func PPReqPrefix

func PPReqPrefix(debug bool, log xlog.XLogger) xhttp.ReqPrefixFunc

PPReqPrefix 闭包注入 logger 和 debug 信息

func PPResSuffix

func PPResSuffix(debug bool, log xlog.XLogger) xhttp.ResSuffixFunc

PPResSuffix 闭包注入 logger 和 debug 信息

Types

type Client

type Client struct {
	// 配置组
	config.Config

	// 操作组
	operate.Operates
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, ops ...Settings) (client *Client, err error)

NewClient 初始化 Paypal 客户端

func (*Client) AcceptClaim

func (c *Client) AcceptClaim(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.AcceptClaimRes, err error)

AcceptClaim 接受索赔(Accept claim) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim Bug:原文有错误,文档中显示上传文件,例子中是正常的 payload fixme : testify

func (*Client) AcceptOffer2Resolve

func (c *Client) AcceptOffer2Resolve(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.AcceptOffer2ResolveRes, err error)

AcceptOffer2Resolve 客户接受商家的解决方案,结束争议(Accept offer to resolve dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer

func (*Client) AckReturnedItem

func (c *Client) AckReturnedItem(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.AckReturnedItemRes, err error)

AckReturnedItem ack 退回的商品(Acknowledge returned item) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_acknowledge-return-item fixme : testify

func (*Client) ActivateSubscription

func (c *Client) ActivateSubscription(ctx context.Context, subscriptionId string, pl paypay.Payload) (res *entity.ActivateSubscriptionRes, err error)

ActivateSubscription 取消订阅(Activate subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate

func (*Client) ActivePlan

func (c *Client) ActivePlan(ctx context.Context, planId string) (res *entity.ActivePlanRes, err error)

ActivePlan 激活计划(Active plan) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate

func (*Client) AddTrackerForOrder

func (c *Client) AddTrackerForOrder(ctx context.Context, orderId string, pl paypay.Payload) (res *entity.AddTrackerForOrderRes, err error)

AddTrackerForOrder 给订单添加物流信息(Add tracking information for an Order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_track_create

func (*Client) AppealDispute

func (c *Client) AppealDispute(ctx context.Context, disputeId string, getFiles func() map[string]paypay.File) (res *entity.AppealDisputeRes, err error)

AppealDispute 上诉(Appeal dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_appeal fixme : testify

func (*Client) AuthorizeOrder

func (c *Client) AuthorizeOrder(ctx context.Context, orderId string, pl paypay.Payload) (res *entity.AuthorizeOrderRes, err error)

AuthorizeOrder 订单支付确认(Authorize payment for order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_authorize

func (*Client) CancelSentInvoice

func (c *Client) CancelSentInvoice(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.CancelSentInvoiceRes, err error)

CancelSentInvoice 取消已发送发票(Cancel sent invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_cancel

func (*Client) CancelSubscription

func (c *Client) CancelSubscription(ctx context.Context, subscriptionId string, pl paypay.Payload) (res *entity.CancelSubscriptionRes, err error)

CancelSubscription 取消订阅(Cancel subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel

func (*Client) CancelUnclaimedPayoutItem

func (c *Client) CancelUnclaimedPayoutItem(ctx context.Context, payoutItemId string) (res *entity.CancelUnclaimedPayoutItemRes, err error)

CancelUnclaimedPayoutItem 取消批量支付中收款人无PayPal账号的项目(Cancel Unclaimed Payout Item)主动取消,超过30天 Paypal 系统自动取消 文档:https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_cancel

func (*Client) CaptureAuthoriedPaymentOnSubscription

func (c *Client) CaptureAuthoriedPaymentOnSubscription(ctx context.Context, subscriptionId string, pl paypay.Payload) (res *entity.CaptureAuthoriedPaymentOnSubscriptionRes, err error)

CaptureAuthoriedPaymentOnSubscription 捕获订阅的授权支付信息(Capture authorized payment on subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture

func (*Client) CaptureAuthorizedPayment

func (c *Client) CaptureAuthorizedPayment(ctx context.Context, authorizationId string, pl paypay.Payload) (res *entity.CaptureAuthorizedPaymentRes, err error)

CaptureAuthorizedPayment 支付授权捕获(Capture authorized payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture

func (*Client) CaptureOrder

func (c *Client) CaptureOrder(ctx context.Context, orderId string, pl paypay.Payload) (res *entity.CaptureOrderRes, err error)

CaptureOrder 订单支付确认(Capture payment for order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_capture

func (*Client) ConfirmOrder

func (c *Client) ConfirmOrder(ctx context.Context, orderId string, pl paypay.Payload) (res *entity.ConfirmOrderRes, err error)

ConfirmOrder 订单支付确认(Confirm the Order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_confirm

func (*Client) CreateBatchPayout

func (c *Client) CreateBatchPayout(ctx context.Context, pl paypay.Payload) (res *entity.CreateBatchPayoutRes, err error)

CreateBatchPayout 创建批量支付(Create batch payout) 文档:https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_post

func (*Client) CreateInvoice

func (c *Client) CreateInvoice(ctx context.Context, pl paypay.Payload) (res *entity.CreateInvoiceRes, err error)

CreateInvoice 创建虚拟发票(Create draft invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create

func (*Client) CreateInvoiceTemplate

func (c *Client) CreateInvoiceTemplate(ctx context.Context, pl paypay.Payload) (res *entity.CreateInvoiceTemplateRes, err error)

CreateInvoiceTemplate 创建发票模板(Create template) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#templates_create

func (*Client) CreateOrder

func (c *Client) CreateOrder(ctx context.Context, pl paypay.Payload) (res *entity.CreateOrderRes, err error)

CreateOrder 创建订单(Create order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_create

func (*Client) CreatePlan

func (c *Client) CreatePlan(ctx context.Context, pl paypay.Payload) (res *entity.CreatePlanRes, err error)

CreatePlan 创建计划(Create Plan) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create

func (*Client) CreateProduct

func (c *Client) CreateProduct(ctx context.Context, pl paypay.Payload) (res *entity.CreateProductRes, err error)

CreateProduct 创建目录商品(Create product) 文档:https://developer.paypal.com/docs/api/catalog-products/v1/#products_create

func (*Client) CreateSubscription

func (c *Client) CreateSubscription(ctx context.Context, pl paypay.Payload) (res *entity.CreateSubscriptionRes, err error)

CreateSubscription 创建订阅(Create subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create

func (*Client) CustomCallOnce

func (c *Client) CustomCallOnce(
	ctx context.Context,
	method Method,
	getKV func() map[string]string,
	pl paypay.Payload,
	query paypay.Payload,
	patches []*entity.Patch,
	emptyRes entity.EmptyRes,
	response interface{},
	ops ...Settings) error

CustomCallOnce single call with custom settings @params: ctx = context of any function caller

@params: method = Paypal request predefined info

@params: getKv = placeholder and target value of uri eg:

/v2/checkout/orders/{{.order_id}}?{{.params}}
getKv can be : func() map[string]string {return map[string]string{OrderId.String(): "yourId"}}
you can skip params because its a build-in placeholder no need concerned from outside of the function.
will return an error if getKv is nil.

@params: pl = payload you build to make a http request. should be nil if no use.

@params: query = will transform to urlparams and attached to uri in method. should be nil if no use.

@params: patches = payload of your changes in update* requests. should be nil if no use.

@params: emptyRes = err msg in case there`s sth. wrong with the request.

@params: response

@params: ops = custom settings you want to use in this request.

you can check out usage in examples

func (*Client) DeactivePlan

func (c *Client) DeactivePlan(ctx context.Context, planId string) (res *entity.DeactivePlanRes, err error)

DeactivePlan 暂停计划(Deactive plan) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate

func (*Client) DeleteExternalPayment

func (c *Client) DeleteExternalPayment(ctx context.Context, invoiceId, transactionId string) (res *entity.DeleteExternalPaymentRes, err error)

DeleteExternalPayment 删除额外支付(Delete external payment) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete

func (*Client) DeleteExternalRefund

func (c *Client) DeleteExternalRefund(ctx context.Context, invoiceId, transactionId string) (res *entity.DeleteExternalRefundRes, err error)

DeleteExternalRefund 删除额外支付(Delete external refund) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete

func (*Client) DeleteInvoice

func (c *Client) DeleteInvoice(ctx context.Context, invoiceId string) (res *entity.DeleteInvoiceRes, err error)

DeleteInvoice 删除发票(Delete invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_delete

func (*Client) DeleteInvoiceTemplate

func (c *Client) DeleteInvoiceTemplate(ctx context.Context, templateId string) (res *entity.DeleteInvoiceTemplateRes, err error)

DeleteInvoiceTemplate 删除发票模板(Delete template) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_delete

func (*Client) DenyOffer2Resolve

func (c *Client) DenyOffer2Resolve(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.DenyOffer2ResolveRes, err error)

DenyOffer2Resolve 拒绝方案(Deny offer to resolve dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer

func (*Client) EscalateDisputeToClaim

func (c *Client) EscalateDisputeToClaim(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.EscalateDisputeToClaimRes, err error)

EscalateDisputeToClaim 将投诉升级为索赔(Escalate dispute to claim) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_escalate make sure dispute lifecycle must be INQUIRY.

func (*Client) FullyUpdateInvoice

func (c *Client) FullyUpdateInvoice(ctx context.Context, invoiceId string, query, pl paypay.Payload) (res *entity.FullyUpdateInvoiceRes, err error)

FullyUpdateInvoice 更新发票(Fully update invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update

func (*Client) FullyUpdateInvoiceTemplate

func (c *Client) FullyUpdateInvoiceTemplate(ctx context.Context, templateId string, pl paypay.Payload) (res *entity.FullyUpdateInvoiceTemplateRes, err error)

FullyUpdateInvoiceTemplate 更新发票模板(Fully update template) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#templates_update

func (*Client) GenerateInvoiceNumber

func (c *Client) GenerateInvoiceNumber(ctx context.Context, pl paypay.Payload) (res *entity.GenerateInvoiceNumberRes, err error)

GenerateInvoiceNumber 生成发票码(Generate invoice number) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoicing_generate-next-invoice-number

func (*Client) GenerateInvoiceQRCode

func (c *Client) GenerateInvoiceQRCode(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.GenerateInvoiceQRCodeRes, err error)

GenerateInvoiceQRCode 生成发票二维码(Generate QR code) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code

func (*Client) ListAllBalances

func (c *Client) ListAllBalances(ctx context.Context, query paypay.Payload) (res *entity.ListAllBalancesRes, err error)

ListAllBalances 获取所有余额 (List all balances) 文档:https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get

func (*Client) ListDisputes

func (c *Client) ListDisputes(ctx context.Context, query paypay.Payload) (res *entity.ListDisputesRes, err error)

ListDisputes 获取争议列表(List disputes) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer

func (*Client) ListInvoice

func (c *Client) ListInvoice(ctx context.Context, query paypay.Payload) (res *entity.ListInvoiceRes, err error)

ListInvoice 发票列表(List invoices) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list

func (*Client) ListInvoiceTemplate

func (c *Client) ListInvoiceTemplate(ctx context.Context, query paypay.Payload) (res *entity.ListInvoiceTemplateRes, err error)

ListInvoiceTemplate 发票模板列表(List templates) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#templates_list

func (*Client) ListPlans

func (c *Client) ListPlans(ctx context.Context, query paypay.Payload) (res *entity.ListPlansRes, err error)

ListPlans 展示订阅计划(List plans) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list

func (*Client) ListProducts

func (c *Client) ListProducts(ctx context.Context, query paypay.Payload) (res *entity.ListProductsRes, err error)

ListProducts 商品列表(List products) 文档:https://developer.paypal.com/docs/api/catalog-products/v1/#products_list

func (*Client) ListTransactions

func (c *Client) ListTransactions(ctx context.Context, query paypay.Payload) (res *entity.ListTransactionsRes, err error)

ListTransactions 交易列表 (List transactions) 文档:https://developer.paypal.com/docs/api/transaction-search/v1/#search_get

func (*Client) ListTransactions4Subscription

func (c *Client) ListTransactions4Subscription(ctx context.Context, subscriptionId string, query paypay.Payload) (res *entity.ListTransactions4SubscriptionRes, err error)

ListTransactions4Subscription 列出一个订阅的所有交易记录 (List transactions for subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions

func (*Client) MakeOffer2Resolve

func (c *Client) MakeOffer2Resolve(ctx context.Context, disputeId string, pl paypay.Payload) (res *entity.MakeOffer2ResolveRes, err error)

MakeOffer2Resolve 发起方案(Make offer to resolve dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_make-offer

func (*Client) NotifyDispute2ThirdParty

func (c *Client) NotifyDispute2ThirdParty(ctx context.Context, disputeId string, getFiles func() map[string]paypay.File) (res *entity.NotifyDispute2ThirdPartyRes, err error)

NotifyDispute2ThirdParty 向第三方发送相关内容(Send message about dispute to other party) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_send-message fixme : testify

func (*Client) PartiallyUpdateDispute

func (c *Client) PartiallyUpdateDispute(ctx context.Context, disputeId string, patches []*entity.Patch) (res *entity.PartiallyUpdateDisputeRes, err error)

PartiallyUpdateDispute 更新争议(Update dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch

func (*Client) Print

func (c *Client) Print()

func (*Client) ProvideEvidence

func (c *Client) ProvideEvidence(ctx context.Context, disputeId string, getFiles func() map[string]paypay.File) (res *entity.ProvideEvidenceRes, err error)

ProvideEvidence 上诉(Provide evidence) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence fixme : testify

func (*Client) ProvideInfo4Dispute

func (c *Client) ProvideInfo4Dispute(ctx context.Context, disputeId string, getFiles func() map[string]paypay.File) (res *entity.ProvideInfo4DisputeRes, err error)

ProvideInfo4Dispute 提供有效信息(Provide supporting information for dispute) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-supporting-info fixme : testify

func (*Client) ReauthorizePayment

func (c *Client) ReauthorizePayment(ctx context.Context, authorizationId string, pl paypay.Payload) (res *entity.ReauthorizePaymentRes, err error)

ReauthorizePayment 重新授权支付授权(Reauthorize authorized payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize

func (*Client) RecordPaymentForInvoice

func (c *Client) RecordPaymentForInvoice(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.RecordPaymentForInvoiceRes, err error)

RecordPaymentForInvoice 记录发票付款(Record payment for invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments

func (*Client) RecordRefundForInvoice

func (c *Client) RecordRefundForInvoice(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.RecordRefundForInvoiceRes, err error)

RecordRefundForInvoice 记录发票退款(Record refund for invoice) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds

func (*Client) RefundCapturedPayment

func (c *Client) RefundCapturedPayment(ctx context.Context, captureId string, pl paypay.Payload) (res *entity.RefundCapturedPaymentRes, err error)

RefundCapturedPayment 支付捕获退款(Refund captured payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#captures_refund

func (*Client) RevisePlanOrQuantityOfSubsription

func (c *Client) RevisePlanOrQuantityOfSubsription(ctx context.Context, subscriptionId string) (res *entity.RevisePlanOrQuantityOfSubsriptionRes, err error)

ShowSubscriptionDetails 更新计划或者数量(Revise plan or quantity of subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise

func (*Client) SearchInvoice

func (c *Client) SearchInvoice(ctx context.Context, query, pl paypay.Payload) (res *entity.SearchInvoiceRes, err error)

SearchInvoice 查询发票(Search for invoices) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_search-invoices

func (*Client) SendInvoice

func (c *Client) SendInvoice(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.SendInvoiceRes, err error)

SendInvoice 发票列表(List invoices) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send

func (*Client) SendInvoiceReminder

func (c *Client) SendInvoiceReminder(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.SendInvoiceReminderRes, err error)

SendInvoiceReminder 发票列表(List invoices) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send

func (*Client) ShowAuthorizedPaymentDetails

func (c *Client) ShowAuthorizedPaymentDetails(ctx context.Context, authorizationId string) (res *entity.ShowAuthorizedPaymentDetailsRes, err error)

ShowAuthorizedPaymentDetails 支付授权详情(Show details for authorized payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#authorizations_get

func (*Client) ShowCapturedPayment

func (c *Client) ShowCapturedPayment(ctx context.Context, captureId string) (res *entity.ShowCapturedPaymentRes, err error)

ShowCapturedPayment 支付捕获详情(Show captured payment details) 文档:https://developer.paypal.com/docs/api/payments/v2/#captures_get

func (*Client) ShowDisputeDetails

func (c *Client) ShowDisputeDetails(ctx context.Context, disputeId string) (res *entity.ShowDisputeDetailsRes, err error)

ShowDisputeDetails 获取争议详情c(Show dispute details) 文档:https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_get

func (*Client) ShowInvoiceDetail

func (c *Client) ShowInvoiceDetail(ctx context.Context, invoiceId string, pl paypay.Payload) (res *entity.ShowInvoiceDetailRes, err error)

ShowInvoiceDetail 查看发票详情(Show invoice details) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get

func (*Client) ShowOrderDetails

func (c *Client) ShowOrderDetails(ctx context.Context, orderId string, query paypay.Payload) (res *entity.ShowOrderDetailsRes, err error)

ShowOrderDetails 查看订单详情(Show order details) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_get

func (*Client) ShowPayoutBatchDetail

func (c *Client) ShowPayoutBatchDetail(ctx context.Context, batchId string, query paypay.Payload) (res *entity.ShowPayoutBatchDetailRes, err error)

ShowPayoutBatchDetail 查看批量支付详情(Show payout batch details) 文档:https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_get

func (*Client) ShowPayoutItemDetail

func (c *Client) ShowPayoutItemDetail(ctx context.Context, payoutItemId string) (res *entity.ShowPayoutItemDetailRes, err error)

ShowPayoutItemDetail 查看支付详情(Show payout detail) 文档:https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get

func (*Client) ShowPlanDetails

func (c *Client) ShowPlanDetails(ctx context.Context, planId string) (res *entity.ShowPlanDetailsRes, err error)

ShowPlanDetails 展示计划(show plan details) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get

func (*Client) ShowProductDetails

func (c *Client) ShowProductDetails(ctx context.Context, productId string) (res *entity.ShowProductDetailsRes, err error)

ShowProductDetails 查看商品详情(Show product details) 文档:https://developer.paypal.com/docs/api/catalog-products/v1/#products_get

func (*Client) ShowRefundDetails

func (c *Client) ShowRefundDetails(ctx context.Context, refundId string) (res *entity.ShowRefundDetailsRes, err error)

ShowRefundDetails 支付捕获退款(Refund captured payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#captures_refund

func (*Client) ShowSubscriptionDetails

func (c *Client) ShowSubscriptionDetails(ctx context.Context, subscriptionId string) (res *entity.ShowSubscriptionDetailsRes, err error)

ShowSubscriptionDetails 查看订阅详情(Show subscription details) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get

func (*Client) ShowTemplateDetails

func (c *Client) ShowTemplateDetails(ctx context.Context, templateId string, _ paypay.Payload) (res *entity.ShowTemplateDetailsRes, err error)

ShowTemplateDetails 查看模板详情(Show template details) 文档:https://developer.paypal.com/docs/api/invoicing/v2/#templates_get

func (*Client) SuspendSubscription

func (c *Client) SuspendSubscription(ctx context.Context, subscriptionId string, pl paypay.Payload) (res *entity.SuspendSubscriptionRes, err error)

SuspendSubscription 暂定订阅(Suspend subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend

func (*Client) TrackersOfOrder

func (c *Client) TrackersOfOrder(ctx context.Context, orderId, trackerId string, patches []*entity.Patch) (res *entity.TrackersOfOrderRes, err error)

TrackersOfOrder 更新或取消物流信息(Update or cancel tracking information for a PayPal order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_trackers_patch

func (*Client) UpdateOrder

func (c *Client) UpdateOrder(ctx context.Context, orderId string, patches []*entity.Patch) (res *entity.UpdateOrderRes, err error)

UpdateOrder 更新订单(Update order) 文档:https://developer.paypal.com/docs/api/orders/v2/#orders_patch

func (*Client) UpdatePlan

func (c *Client) UpdatePlan(ctx context.Context, planId string, patches []*entity.Patch) (res *entity.UpdatePlanRes, err error)

UpdatePlan 更新计划(Update plan) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_patch

func (*Client) UpdatePricing

func (c *Client) UpdatePricing(ctx context.Context, planId string) (res *entity.UpdatePricingRes, err error)

UpdatePricing 更新计划价格方案(Update pricing) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes

func (*Client) UpdateProduct

func (c *Client) UpdateProduct(ctx context.Context, productId string, patches []*entity.Patch) (res *entity.UpdateProductRes, err error)

UpdateProduct 更新商品(Update product) 文档:https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch

func (*Client) UpdateSubscription

func (c *Client) UpdateSubscription(ctx context.Context, subscriptionId string, patches []*entity.Patch) (res *entity.UpdateSubscriptionRes, err error)

UpdateSubscription 更新订阅(Update subscription) 文档:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch

func (*Client) Use

func (c *Client) Use(ops ...Settings) *Client

func (*Client) VoidAuthorizePayment

func (c *Client) VoidAuthorizePayment(ctx context.Context, authorizationId string, pl paypay.Payload) (res *entity.VoidAuthorizePaymentRes, err error)

VoidAuthorizePayment 作废支付授权(Void authorized payment) 文档:https://developer.paypal.com/docs/api/payments/v2/#authorizations_void

type DoPayPalRequest

type DoPayPalRequest func(ctx context.Context, uri string, urlGenerator func(string) string, pl paypay.Payload, patches []*entity.Patch) (res *http.Response, bs []byte, err error)

func DeletePayPal

func DeletePayPal(c *Client) DoPayPalRequest

func EmptyPaypal

func EmptyPaypal(c *Client) DoPayPalRequest

func GetPayPal

func GetPayPal(c *Client) DoPayPalRequest

func PatchPayPal

func PatchPayPal(c *Client) DoPayPalRequest

func PostPayPal

func PostPayPal(c *Client) DoPayPalRequest

func PutPayPal

func PutPayPal(c *Client) DoPayPalRequest

func UploadFilePaypal

func UploadFilePaypal(c *Client, files map[string]paypay.File, ops ...xhttp.CfgOp) DoPayPalRequest

type Method

type Method struct {
	Uri             string
	ValidStatusCode int
	Do              func(c *Client) DoPayPalRequest
	Checker         paypay.PayloadRuler
}
var (
	// CreateOrder 创建订单 POST
	CreateOrder Method = Method{
		Uri:             "/v2/checkout/orders",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/checkout/orders": []paypay.Ruler{
				paypay.NewRuler("purchase_units",
					`purchase_units != nil && len(purchase_units) <= 10 &&
all(purchase_units, {.Amount != nil}) `,
					"purchase_units 最多一次性传入10个",
				),
				paypay.NewRuler("intent", `intent in ["CAPTURE", "AUTHORIZE"]`, ""),
			},
		}),
	}
	// ShowOrderDetails order_id 查看订单详情 GET
	ShowOrderDetails Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// UpdateOrder order_id 更新订单 PATCH
	UpdateOrder Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PatchPayPal,
	}
	// ConfirmOrder order_id 订单支付确认 POST
	ConfirmOrder Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}/confirm-payment-source",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/checkout/orders/{{.order_id}}/confirm-payment-source": []paypay.Ruler{
				paypay.NewRuler("payment_source", `payment_source != nil`, "payment_source 不为空"),
			},
		}),
	}
	// AuthorizeOrder order_id 订单支付授权 POST
	AuthorizeOrder Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}/authorize",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
	}
	// CaptureOrder order_id 订单支付捕获 POST
	CaptureOrder Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}/capture",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/checkout/orders/{{.order_id}}/capture": []paypay.Ruler{
				paypay.NewRuler("payment_source", `payment_source != nil`, "payment_source 不为空"),
			},
		}),
	}
	// AddTracking4Order order_id 订单追踪 POST
	AddTracking4Order Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}/track",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/checkout/orders/{{.order_id}}/track": []paypay.Ruler{
				paypay.NewRuler("tracking_number", `tracking_number != nil`, "运单号不为空"),
				paypay.NewRuler("carrier", `carrier != nil`, "承运机构不为空"),
				paypay.NewRuler("capture_id", `capture_id != nil`, "capture_id 不为空"),
			},
		}),
	}
	// UpOrCancelTracking4Order order_id, tracker_id 更新或取消订单追踪 POST
	UpOrCancelTracking4Order Method = Method{
		Uri:             "/v2/checkout/orders/{{.order_id}}/trackers/{{.tracker_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
)

订单相关

var (
	// ShowAuthorizedPaymentDetails authorization_id 支付授权详情 GET
	ShowAuthorizedPaymentDetails Method = Method{
		Uri:             "/v2/payments/authorizations/{{.authorization_id}}",
		ValidStatusCode: http.StatusCreated,
		Do:              GetPayPal,
	}
	// CaptureAuthorizedPayment authorization_id 支付授权捕获 POST
	CaptureAuthorizedPayment Method = Method{
		Uri:             "/v2/payments/authorizations/{{.authorization_id}}/capture",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
	}
	// ReauthorizePayment authorization_id 重新授权支付授权 POST
	ReauthorizePayment Method = Method{
		Uri:             "/v2/payments/authorizations/{{.authorization_id}}/reauthorize",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
	}
	// VoidAuthorizePayment authorization_id 作废支付授权 POST
	VoidAuthorizePayment Method = Method{
		Uri:             "/v2/payments/authorizations/{{.authorization_id}}/void",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	// ShowCapturedPayment capture_id 支付捕获详情 GET
	ShowCapturedPayment Method = Method{
		Uri:             "/v2/payments/captures/{{.capture_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// RefundCapturedPayment capture_id 支付捕获退款 POST
	RefundCapturedPayment Method = Method{
		Uri:             "/v2/payments/captures/{{.capture_id}}/refund",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
	}
	// ShowRefundDetails refund_id 支付退款详情 GET
	ShowRefundDetails Method = Method{
		Uri:             "/v2/payments/refunds/{{.refund_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
)

支付相关

var (
	// CreateBatchPayout 创建批量支付 POST
	CreateBatchPayout Method = Method{
		Uri:             "/v1/payments/payouts",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/payments/payouts": []paypay.Ruler{
				paypay.NewRuler("items", `items != nil`, "支付详情列表不能为空"),
				paypay.NewRuler("sender_batch_header", `sender_batch_header != nil`, "批次号不能为空"),
			},
		}),
	}
	// ShowPayoutBatchDetail payout_batch_id 获取批量支付详情 GET
	ShowPayoutBatchDetail Method = Method{
		Uri:             "/v1/payments/payouts/{{.payout_batch_id}}?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// ShowPayoutItemDetail payout_item_id 获取支付项目详情 GET
	ShowPayoutItemDetail Method = Method{
		Uri:             "/v1/payments/payouts-item/{{.payout_item_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// CancelUnclaimedPayoutItem payout_item_id 取消支付项目 POST
	CancelUnclaimedPayoutItem Method = Method{
		Uri:             "/v1/payments/payouts-item/{{.payout_item_id}}/cancel",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
)

支付 Payouts

var (
	// CreateInvoices 创建发票 POST
	CreateInvoices Method = Method{
		Uri:             "/v2/invoicing/invoices",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// ListInvoices 查看发票列表 GET
	ListInvoices Method = Method{
		Uri:             "/v2/invoicing/invoices?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// SendInvoice invoice_id 发送发票 POST
	SendInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/send",
		ValidStatusCode: http.StatusAccepted,
		Do:              PostPayPal,
	}
	// SendInvoiceReminder invoice_id 发送发票提醒 POST
	SendInvoiceReminder Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/remind",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	// CancelSentInvoice invoice_id 取消已发送发票 POST
	CancelSentInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/cancel",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	// RecordPaymentForInvoice invoice_id 记录发票付款 POST
	RecordPaymentForInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/payments",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/invoicing/invoices/{{.invoice_id}}/payments": []paypay.Ruler{
				paypay.NewRuler(
					"method",
					`method != nil && method in [BANK_TRANSFER, CASH, CHECK, CREDIT_CARD, DEBIT_CARD, PAYPAL, WIRE_TRANSFER, OTHER]`,
					"支付方案不能为空且要在以下内容中选取 [BANK_TRANSFER, CASH, CHECK, CREDIT_CARD, DEBIT_CARD, PAYPAL, WIRE_TRANSFER, OTHER]"),
			},
		}),
	}
	// DeleteExternalPayment invoice_id,transaction_id 删除额外支付 DELETE
	DeleteExternalPayment Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/payments/{{.transaction_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              DeletePayPal,
	}
	// RecordRefundForInvoice invoice_id 记录发票退款 POST
	RecordRefundForInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/refunds",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/invoicing/invoices/{{.invoice_id}}/payments": []paypay.Ruler{
				paypay.NewRuler(
					"method",
					`method != nil && method in [BANK_TRANSFER, CASH, CHECK, CREDIT_CARD, DEBIT_CARD, PAYPAL, WIRE_TRANSFER, OTHER]`,
					"支付方案不能为空且要在以下内容中选取 [BANK_TRANSFER, CASH, CHECK, CREDIT_CARD, DEBIT_CARD, PAYPAL, WIRE_TRANSFER, OTHER]"),
			},
		}),
	}
	// DeleteExternalRefund invoice_id,transaction_id 删除额外退款 DELETE
	DeleteExternalRefund Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/refunds/{{.transaction_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              DeletePayPal,
	}
	// GenerateInvoiceQRCode invoice_id 生成发票二维码 POST
	GenerateInvoiceQRCode Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}/generate-qr-code",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// GenerateInvoiceNumber 生成下个发票号码 POST
	GenerateInvoiceNumber Method = Method{
		Uri:             "/v2/invoicing/generate-next-invoice-number",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// ShowInvoiceDetail invoice_id 获取发票详情 GET
	ShowInvoiceDetail Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// FullyUpdateInvoice invoice_id 全量更新发票 PUT
	FullyUpdateInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              PutPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v2/invoicing/invoices/{{.invoice_id}}?{{.params}}": []paypay.Ruler{
				paypay.NewRuler("detail", `detail != nil`, "detail 不为空"),
			},
		}),
	}
	// DeleteInvoice // invoice_id 删除发票 DELETE
	DeleteInvoice Method = Method{
		Uri:             "/v2/invoicing/invoices/{{.invoice_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              DeletePayPal,
	}
	// SearchInvoice 搜索发票 POST
	SearchInvoice Method = Method{
		Uri:             "/v2/invoicing/search-invoices?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker:         nil,
	}
	// ListInvoiceTemplate 获取发票模板列表 GET
	ListInvoiceTemplate Method = Method{
		Uri:             "/v2/invoicing/templates?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// CreateInvoiceTemplate 创建发票模板 POST
	CreateInvoiceTemplate Method = Method{
		Uri:             "/v2/invoicing/templates",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// ShowTemplateDetails template_id 获取模版详情 GET
	ShowTemplateDetails Method = Method{
		Uri:             "/v2/invoicing/templates/{{.template_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// FullyUpdateInvoiceTemplate template_id 全量更新发票模板 PUT
	FullyUpdateInvoiceTemplate Method = Method{
		Uri:             "/v2/invoicing/templates/{{.template_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              PutPayPal,
	}
	// DeleteInvoiceTemplate template_id 删除发票模板 DELETE
	DeleteInvoiceTemplate Method = Method{
		Uri:             "/v2/invoicing/templates/{{.template_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              DeletePayPal,
	}
)

发票 Invoices

var (
	// CreatePlan 创建订阅 POST
	CreatePlan Method = Method{
		Uri:             "/v1/billing/plans",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/plans": []paypay.Ruler{
				paypay.NewRuler("product_id", `product_id != nil`, "通过目录产品 API 创建的产品的 ID 不为空"),
				paypay.NewRuler("name", `name != nil`, "计划名 不为空"),
				paypay.NewRuler("billing_cycles", `billing_cycles != nil`, "billing_cycles 不为空"),
				paypay.NewRuler("payment_preferences", `payment_preferences != nil`, "payment_preferences 不为空"),
				paypay.NewRuler("status", `(status != nil && status in ["CREATED", "INACTIVE", "ACTIVE"]) || status == nil`,
					"status 默认 ACTIVE 或者 枚举值有误:ACTIVE,INACTIVE,CREATED"),
			},
		}),
	}
	// ListPlans 列表展示计划 GET
	ListPlans Method = Method{
		Uri:             "/v1/billing/plans?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// ShowPlanDetails plan_id 展示计划详情 GET
	ShowPlanDetails Method = Method{
		Uri:             "/v1/billing/plans/{{.plan_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// UpdatePlan plan_id 更新计划 patch
	UpdatePlan Method = Method{
		Uri:             "/v1/billing/plans/{{.plan_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PatchPayPal,
	}
	// ActivePlan plan_id 激活计划 POST
	ActivePlan Method = Method{
		Uri:             "/v1/billing/plans/{{.plan_id}}/activate",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	DeactivePlan Method = Method{
		Uri:             "/v1/billing/plans/{{.plan_id}}/deactivate",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	// UpdatePricing plan_id 更新计划价格方案 POST
	UpdatePricing Method = Method{
		Uri:             "/v1/billing/plans/{{.plan_id}}/update-pricing-schemes",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}

	// CreateSubscription 创建订阅 POST
	CreateSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/subscriptions": []paypay.Ruler{
				paypay.NewRuler("plan_id", `plan_id != nil`, "plan_id 不为空"),
			},
		}),
	}
	// ShowSubscriptionDetails subscription_id 展示订阅详情 GET
	ShowSubscriptionDetails Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// UpdateSubscription subscription_id 更新订阅 PATCH
	UpdateSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PatchPayPal,
	}
	// RevisePlanOrQuantityOfSubsription subscription_id 更新计划或者数量 POST
	RevisePlanOrQuantityOfSubsription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/revise",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// SuspendSubscription subscription_id 暂定订阅计划 POST
	SuspendSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/suspend",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/subscriptions/{{.subscription_id}}/suspend": []paypay.Ruler{
				paypay.NewRuler("reason", `reason != nil`, "暂定原因 reason 不为空"),
			},
		}),
	}
	// CancelSubscription subscription_id 取消订阅 POST
	CancelSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/cancel",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/subscriptions/{{.subscription_id}}/cancel": []paypay.Ruler{
				paypay.NewRuler("reason", `reason != nil`, "取消原因 reason 不为空"),
			},
		}),
	}
	// ActivateSubscription subscription_id 激活订阅 POST
	ActivateSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/activate",
		ValidStatusCode: http.StatusNoContent,
		Do:              PostPayPal,
	}
	// CaptureAuthoriedPaymentOnSubscription subscription_id 捕获订阅的授权支付信息 POST
	CaptureAuthoriedPaymentOnSubscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/capture",
		ValidStatusCode: http.StatusAccepted,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/subscriptions/{{.subscription_id}}/capture": []paypay.Ruler{
				paypay.NewRuler("note", `note != nil`, "note 不为空"),
				paypay.NewRuler("capture_type", `capture_type == "OUTSTANDING_BALANCE"`, "capture_type = OUTSTANDING_BALANCE The outstanding balance that the subscriber must clear"),
				paypay.NewRuler("amount", `amount != nil && amount.currency_code != nil && amount.value != nil`, "amount 及其字段不为空"),
			},
		}),
	}
	// ListTransactions4Subscription subscription_id 列出一个订阅的所有交易记录
	ListTransactions4Subscription Method = Method{
		Uri:             "/v1/billing/subscriptions/{{.subscription_id}}/transactions?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/billing/subscriptions/{{.subscription_id}}/transactions": []paypay.Ruler{
				paypay.NewRuler("start_time", `start_time != nil`, "query 参数 start_time 不为空"),
				paypay.NewRuler("end_time", `end_time != nil`, "query 参数 end_time 不为空"),
			},
		}),
	}
)

订阅 类似支付宝周期扣款

var (
	// ListTransactions 交易列表
	ListTransactions Method = Method{
		Uri:             "/v1/reporting/transactions?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/reporting/transactions": []paypay.Ruler{
				paypay.NewRuler("start_date", `start_date != nil`, "query 参数 start_date 不为空"),
				paypay.NewRuler("end_date", `end_date != nil`, "query 参数 end_date 不为空"),
			},
		}),
	}
	// ListAllBalances 获取所有余额
	ListAllBalances Method = Method{
		Uri:             "/v1/reporting/balances?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
)

Transaction 交易

var (
	// CreateProduct 创建商品 POST
	CreateProduct Method = Method{
		Uri:             "/v1/catalogs/products",
		ValidStatusCode: http.StatusCreated,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/catalogs/products": []paypay.Ruler{
				paypay.NewRuler("name", `name != nil`, "产品名不为空"),
			},
		}),
	}
	// ListProducts 商品列表 GET
	ListProducts Method = Method{
		Uri:             "/v1/catalogs/products",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// ShowProductDetails product_id 获取商品详情 GET
	ShowProductDetails Method = Method{
		Uri:             "/v1/catalogs/products/{{.product_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// UpdateProduct product_id 更新商品 PATCH
	UpdateProduct Method = Method{
		Uri:             "/v1/catalogs/products/{{.product_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PatchPayPal,
	}
)

Catalog Products 目录商品

var (
	// EscalateDisputeToClaim dispute_id 将投诉升级为索赔 POST
	EscalateDisputeToClaim Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/escalate",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/customer/disputes/{{.dispute_id}}/escalate": []paypay.Ruler{
				paypay.NewRuler("note", `note != nil`, "note 不为空"),
			},
		}),
	}
	// AcceptOffer2Resolve dispute_id 客户接受商家的解决方案,结束争议 POST
	AcceptOffer2Resolve Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/accept-offer",
		ValidStatusCode: http.StatusAccepted,
		Do:              PostPayPal,
	}
	// ListDisputes 获取争议列表 GET
	ListDisputes Method = Method{
		Uri:             "/v1/customer/disputes?{{.params}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// ProvideInfo4Dispute dispute_id 提供有效信息 POST
	ProvideInfo4Dispute Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/provide-supporting-info",
		ValidStatusCode: http.StatusOK,
		Do:              EmptyPaypal,
	}
	// ShowDisputeDetails dispute_id 获取争议详情 GET
	ShowDisputeDetails Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}",
		ValidStatusCode: http.StatusOK,
		Do:              GetPayPal,
	}
	// PartiallyUpdateDispute dispute_id 部分更新 POST
	PartiallyUpdateDispute Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}",
		ValidStatusCode: http.StatusNoContent,
		Do:              PatchPayPal,
	}
	// DenyOffer2Resolve dispute_id 拒绝方案 POST
	DenyOffer2Resolve Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/deny-offer",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// MakeOffer2Resolve dispute_id 发起一个解决方案 POST
	MakeOffer2Resolve Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/make-offer",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
	}
	// AppealDispute dispute_id 上诉 POST
	AppealDispute Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/appeal",
		ValidStatusCode: http.StatusOK,
		Do:              EmptyPaypal,
	}
	ProvideEvidence Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/provide-evidence",
		ValidStatusCode: http.StatusOK,
		Do:              EmptyPaypal,
	}
	AckReturnedItem Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/acknowledge-return-item",
		ValidStatusCode: http.StatusOK,
		Do:              EmptyPaypal,
	}
	NotifyDispute2ThirdParty Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/send-message",
		ValidStatusCode: http.StatusOK,
		Do:              EmptyPaypal,
	}
	AcceptClaim Method = Method{
		Uri:             "/v1/customer/disputes/{{.dispute_id}}/accept-claim",
		ValidStatusCode: http.StatusOK,
		Do:              PostPayPal,
		Checker: paypay.InjectRuler(map[string][]paypay.Ruler{
			"/v1/customer/disputes/{{.dispute_id}}/accept-claim": []paypay.Ruler{
				paypay.NewRuler("note", `note != nil`, "note 不为空"),
			},
		}),
	}
)

Disputes 投诉 || 争议

var EmptyMethod Method = Method{
	Uri:             "",
	ValidStatusCode: http.StatusOK,
	Do:              EmptyPaypal,
}

type QueryPlaceholder

type QueryPlaceholder string
var (
	OrderId         QueryPlaceholder = "order_id"
	TrackerId       QueryPlaceholder = "tracker_id"
	AuthorizationId QueryPlaceholder = "authorization_id"
	CaptureId       QueryPlaceholder = "capture_id"
	RefundId        QueryPlaceholder = "refund_id"
	PayoutItemId    QueryPlaceholder = "payout_item_id"
	InvoiceId       QueryPlaceholder = "invoice_id"
	TemplateId      QueryPlaceholder = "template_id"
	SubscriptionId  QueryPlaceholder = "subscription_id"
	PlanId          QueryPlaceholder = "plan_id"
	ProductId       QueryPlaceholder = "product_id"
	DisputeId       QueryPlaceholder = "dispute_id"
)

func (QueryPlaceholder) String

func (qp QueryPlaceholder) String() string

type Settings

type Settings func(*Client)

func Checker

func Checker(checker paypay.PayloadRuler) Settings

func ClientID

func ClientID(cid string) Settings

func Debug

func Debug(d bool) Settings

func DefaultChecker

func DefaultChecker() Settings

func DefaultHClient

func DefaultHClient() Settings

func DefaultHeaders

func DefaultHeaders() Settings

func DefaultLogger

func DefaultLogger() Settings

func DefaultPrefixFunc

func DefaultPrefixFunc() Settings

func DefaultSettings

func DefaultSettings(ins ...Settings) []Settings

DefaultSettings 默认沙盒配置,可自定义追加,按照顺序执行,自定义追加的部分会覆盖掉默认内容

func DefaultSuffixFunc

func DefaultSuffixFunc() Settings

func HClient

func HClient(hc xhttp.HttpClientWrapper) Settings

func Headers

func Headers(headers map[string]string) Settings

func NewSettings

func NewSettings(ins ...Settings) []Settings

NewSettings 标准初始化配置

func NewToken

func NewToken(ctx context.Context, clientId, clientSecret string) Settings

func PackSettings

func PackSettings(i1 []Settings, i2 ...Settings) []Settings

func PayloadPreSetter

func PayloadPreSetter(setter map[string][]paypay.PayloadPreSetter) Settings

func PrefixFunc

func PrefixFunc(suppress bool, pres ...xhttp.ReqPrefixFunc) Settings

func Prod

func Prod(prod bool) Settings

func Proxy

func Proxy(prod, sandbox string) Settings

func Secret

func Secret(secret string) Settings

func SetLogger

func SetLogger(logger xlog.XLogger) Settings

func SuffixFunc

func SuffixFunc(suppress bool, sufs ...xhttp.ResSuffixFunc) Settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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