paypal

package
v0.0.0-...-7d8afc6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

README

paypal 支付

1. Dispute

PayPal 退款查询

2. Transaction

paypal 交易查询

3. NVP

paypal 支付接入的最简单方法

Documentation

Index

Constants

View Source
const (
	SetExpressCheckout        NVPMethod = "SetExpressCheckout"
	GetExpressCheckoutDetails NVPMethod = "GetExpressCheckoutDetails"
	DoExpressCheckoutPayment  NVPMethod = "DoExpressCheckoutPayment"

	Version124 NVPVersion = "124.0"
)
View Source
const (
	// App const name
	App string = "paypal_app"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	// GetAccessToken AccessToken ...
	GetAccessToken(ctx context.Context) (string, error)

	// 争议查询
	ListDisputes(ctx context.Context) (disputeItems []DisputeItem, error error)
	ShowDisputeDetails(ctx context.Context, disputeID string) (detail ShowDisputeDetailsResp, error error)

	// 交易查询
	//https://developer.paypal.com/docs/api/transaction-search/v1/#transactions_get
	GetTransaction(ctx context.Context, transactionID string, startTime, endTime time.Time) (transaction TransactionInfo, err error)
	GetRefundTransaction(ctx context.Context, startTime, endTime time.Time) (transactions []TransactionInfo, err error)

	//NVP
	SetExpressCheckout(ctx context.Context, req SetExpressCheckoutReq) (SetExpressCheckoutResp, error)
	GetExpressCheckoutDetails(ctx context.Context, req GetExpressCheckoutDetailsReq) (GetExpressCheckoutDetailsResp, error)
	DoExpressCheckoutPayment(ctx context.Context, req GetExpressCheckoutDetailsReq) (GetExpressCheckoutDetailsResp, error)
}

API is an interface for paypal REST APIs https://developer.paypal.com/docs/integration/direct/customer-disputes/

type APICredentials

type APICredentials struct {
	Username  string
	Password  string
	Signature string
}

APICredentials https://developer.paypal.com/docs/nvp-soap-api/apiCredentials/#api-signatures

type AccessTokeResp

type AccessTokeResp struct {
	Scope       string `json:"scope"`
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	AppID       string `json:"app_id"`
	ExpiresIn   int    `json:"expires_in"`
	Nonce       string `json:"nonce"`
}

type Client

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

func NewClient

func NewClient(c Config) *Client

func (*Client) DoExpressCheckoutPayment

func (c *Client) DoExpressCheckoutPayment(ctx context.Context, req GetExpressCheckoutDetailsReq) (GetExpressCheckoutDetailsResp, error)

func (*Client) FiltrateUserRefundDispute

func (c *Client) FiltrateUserRefundDispute(ctx context.Context, disputes []DisputeItem) (userRefundDisputes []DisputeItem)

FiltrateUserRefundDispute filters user refund disputes.

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken always get a token without expire.

func (*Client) GetExpressCheckoutDetails

func (c *Client) GetExpressCheckoutDetails(ctx context.Context, req GetExpressCheckoutDetailsReq) (GetExpressCheckoutDetailsResp, error)

func (*Client) GetRefundTransaction

func (c *Client) GetRefundTransaction(ctx context.Context, startTime, endTime time.Time) (transactions []TransactionInfo, err error)

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, transactionID string, startTime, endTime time.Time) (transaction TransactionInfo, err error)

GetTransaction get first transaction by transactionID time range between startTime and endTime must less than 31 days. https://developer.paypal.com/docs/integration/direct/transaction-search/#list-transactions

curl example

curl -v -X GET https://api-m.sandbox.paypal.com/v1/reporting/transactions?transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Access-Token>"

func (*Client) GetUserRefundDispute

func (c *Client) GetUserRefundDispute(ctx context.Context, disputeID string) (detail ShowDisputeDetailsResp, isUserRefund bool)

GetUserRefundDispute get user refund dispute if this dispute refunded by user.

func (*Client) GetUserRefundDisputedDetails

func (c *Client) GetUserRefundDisputedDetails(ctx context.Context, disputes []DisputeItem) (userRefundDisputeDetailByInvoiceID map[string]ShowDisputeDetailsResp, noInvoiceIDUserRefundDisputeDetails []ShowDisputeDetailsResp)

GetUserRefundDisputedDetails get user refund disputes transaction details. userRefundDisputes is a map where key is invoiceID and value is disputeDetails invoiceID is SDK orderNumber sent to PayPal, details: https://developer.paypal.com/docs/nvp-soap-api/set-express-checkout-nvp

func (*Client) ListDisputes

func (c *Client) ListDisputes(ctx context.Context) (disputeItems []DisputeItem, error error)

ListDisputes list all resolve dispute.

func (*Client) ListOnePageDisputes

func (c *Client) ListOnePageDisputes(ctx context.Context, pagePageToken string) (disputeItems []DisputeItem, nextPageToken string, error error)

ListDisputes list all resolve dispute.

func (*Client) ListOnePageDisputesV2

func (c *Client) ListOnePageDisputesV2(ctx context.Context, pagePageToken string, startTime, endTime time.Time) (disputeItems []DisputeItem, nextPageToken string, error error)

func (*Client) NvpBase

func (c *Client) NvpBase(method NVPMethod) NVPBase

func (*Client) SetExpressCheckout

func (c *Client) SetExpressCheckout(ctx context.Context, req SetExpressCheckoutReq) (SetExpressCheckoutResp, error)

func (*Client) ShowDisputeDetails

func (c *Client) ShowDisputeDetails(ctx context.Context, disputeID string) (detail ShowDisputeDetailsResp, error error)

ShowDisputeDetails get dispute detail by disputeID.

type Config

type Config struct {
	Host                     string         `yaml:"host"`
	ClientID                 string         `yaml:"client_id"`
	Secret                   string         `yaml:"secret"`
	NVPAndSOAPAPICredentials APICredentials `yaml:"api_credentials"`
}

type DisputeItem

type DisputeItem struct {
	DisputeID     string    `json:"dispute_id"`
	CreateTime    time.Time `json:"create_time"`
	UpdateTime    time.Time `json:"update_time"`
	Status        string    `json:"status"`
	Reason        string    `json:"reason"`
	DisputeState  string    `json:"dispute_state"`
	DisputeAmount struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"dispute_amount"`
	Links []HATEOASLink `json:"links"`
}

type DisputedTransaction

type DisputedTransaction struct {
	SellerTransactionID string    `json:"seller_transaction_id"`
	CreateTime          time.Time `json:"create_time"`
	TransactionStatus   string    `json:"transaction_status"`
	GrossAmount         struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"gross_amount"`
	Buyer struct {
		Name string `json:"name"`
	} `json:"buyer"`
	Seller struct {
		Email      string `json:"email"`
		MerchantID string `json:"merchant_id"`
		Name       string `json:"name"`
	} `json:"seller"`
}

type ErrorResp

type ErrorResp map[string]interface{}

func (ErrorResp) Err

func (e ErrorResp) Err(err error) error

Err error caused by http request and response

type GetExpressCheckoutDetailsReq

type GetExpressCheckoutDetailsReq struct {
	Token string `url:"TOKEN"`
}

type GetExpressCheckoutDetailsResp

type GetExpressCheckoutDetailsResp struct {
	Body url.Values
}
type HATEOASLink struct {
	Href   string `json:"href"`
	Rel    string `json:"rel"`
	Method string `json:"method"`
}

type ListDisputesReq

type ListDisputesReq struct {
	DisputeState     string `url:"dispute_state"`
	PageSize         int    `url:"page_size"`
	NextPageToken    string `url:"next_page_token,omitempty"`
	UpdateTimeBefore string `url:"update_time_before,omitempty"`
	UpdateTimeAfter  string `url:"update_time_after,omitempty"`
}

type ListDisputesResp

type ListDisputesResp struct {
	Items []DisputeItem `json:"items"`
	Links []HATEOASLink `json:"links"`
}

type NVPBase

type NVPBase struct {
	Method    string `url:"METHOD"`
	Version   string `url:"VERSION"`
	User      string `url:"USER"`
	Pwd       string `url:"PWD"`
	Signature string `url:"SIGNATURE"`
}

type NVPMethod

type NVPMethod string

type NVPVersion

type NVPVersion string

type SetExpressCheckoutReq

type SetExpressCheckoutReq struct {
	ReturnURL    string `url:"RETURNURL"`
	Amount       string `url:"PAYMENTREQUEST_0_AMT"`
	NoShipping   string `url:"NOSHIPPING"`
	CurrencyCode string `url:"PAYMENTREQUEST_0_CURRENCYCODE"`
	Desc         string `url:"PAYMENTREQUEST_0_DESC"`
	Customer     string `url:"PAYMENTREQUEST_0_CUSTOM"`
	Invoice      string `url:"PAYMENTREQUEST_0_INVNUM"`
	CancelURL    string `url:"CANCELURL"`
}

type SetExpressCheckoutResp

type SetExpressCheckoutResp struct {
	Body url.Values
}

type ShowDisputeDetailsResp

type ShowDisputeDetailsResp struct {
	DisputeID            string                `json:"dispute_id"`
	CreateTime           time.Time             `json:"create_time"`
	UpdateTime           time.Time             `json:"update_time"`
	DisputedTransactions []DisputedTransaction `json:"disputed_transactions"`
	Reason               string                `json:"reason"`
	Status               string                `json:"status"`
	DisputeAmount        struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"dispute_amount"`
	DisputeOutcome struct {
		OutcomeCode    string `json:"outcome_code"`
		AmountRefunded struct {
			CurrencyCode string `json:"currency_code"`
			Value        string `json:"value"`
		} `json:"amount_refunded"`
	} `json:"dispute_outcome"`
}

func (ShowDisputeDetailsResp) GetDisputeIDAndTransactionID

func (s ShowDisputeDetailsResp) GetDisputeIDAndTransactionID() string

type TransactionInfo

type TransactionInfo struct {
	PaypalAccountId           string `json:"paypal_account_id"`
	TransactionId             string `json:"transaction_id"`
	TransactionEventCode      string `json:"transaction_event_code"`
	TransactionInitiationDate string `json:"transaction_initiation_date"`
	TransactionUpdatedDate    string `json:"transaction_updated_date"`
	TransactionAmount         struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"transaction_amount"`
	FeeAmount struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"fee_amount"`
	InsuranceAmount struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"insurance_amount"`
	ShippingAmount struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"shipping_amount"`
	ShippingDiscountAmount struct {
		CurrencyCode string `json:"currency_code"`
		Value        string `json:"value"`
	} `json:"shipping_discount_amount"`
	TransactionStatus     string `json:"transaction_status"`
	TransactionSubject    string `json:"transaction_subject"`
	TransactionNote       string `json:"transaction_note"`
	InvoiceId             string `json:"invoice_id"`
	CustomField           string `json:"custom_field"`
	ProtectionEligibility string `json:"protection_eligibility"`
}

func (*TransactionInfo) GetInvoiceID

func (t *TransactionInfo) GetInvoiceID() string

GetInvoiceID get invoiceID sent to PapPal by method SetExpressCheckout

type TransactionSearchReq

type TransactionSearchReq struct {
	TransactionID     string            `url:"transaction_id,omitempty"`
	Fields            string            `url:"fields"`
	PageSize          int               `url:"page_size"`
	Page              int               `url:"page"`
	StartDate         string            `url:"start_date"`
	EndDate           string            `url:"end_date"`
	TransactionStatus TransactionStatus `url:"transaction_status,omitempty"`
}

https://developer.paypal.com/docs/integration/direct/transaction-search/#list-transactions

type TransactionSearchResp

type TransactionSearchResp struct {
	TransactionDetails []struct {
		TransactionInfo TransactionInfo `json:"transaction_info"`
	} `json:"transaction_details"`
	AccountNumber         string `json:"account_number"`
	LastRefreshedDatetime string `json:"last_refreshed_datetime"`
	Page                  int    `json:"page"`
	TotalItems            int    `json:"total_items"`
	TotalPages            int    `json:"total_pages"`
	Links                 []struct {
		Href   string `json:"href"`
		Rel    string `json:"rel"`
		Method string `json:"method"`
	} `json:"links"`
}

type TransactionStatus

type TransactionStatus string
const (

	// https://developer.paypal.com/docs/api/transaction-search/v1/
	TransactionDeny    TransactionStatus = "D"
	TransactionPending TransactionStatus = "P"
	TransactionSuccess TransactionStatus = "S"
	TransactionRefund  TransactionStatus = "V"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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