Order should include payments & purchase_units (#179)

* Order should include purchase_units

* PayerWithNameAndPhone needs Address for Order

* add SellerProtection to CaptureAmount

* add RecipientType(s)

* add RecipientType(s)

* BatchHeader.BatchStatus values
This commit is contained in:
jrapoport 2020-11-17 01:59:42 -08:00 committed by GitHub
parent 13112c66e5
commit 476102bb76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 35 deletions

View File

@ -11,7 +11,7 @@ const (
type BillingPlanStatus string type BillingPlanStatus string
const ( const (
BillingPlanStatusActive BillingPlanStatus = "ACTIVE" BillingPlanStatusActive BillingPlanStatus = "ACTIVE"
) )
type IntervalUnit string type IntervalUnit string
@ -65,6 +65,7 @@ const (
//Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#definition-transaction //Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#definition-transaction
type SubscriptionTransactionStatus string type SubscriptionTransactionStatus string
const ( const (
SubscriptionCaptureStatusCompleted SubscriptionTransactionStatus = "COMPLETED" SubscriptionCaptureStatusCompleted SubscriptionTransactionStatus = "COMPLETED"
SubscriptionCaptureStatusDeclined SubscriptionTransactionStatus = "DECLINED" SubscriptionCaptureStatusDeclined SubscriptionTransactionStatus = "DECLINED"
@ -74,11 +75,12 @@ const (
) )
type CaptureType string type CaptureType string
const ( const (
CaptureTypeOutstandingBalance CaptureType = "OUTSTANDING_BALANCE" CaptureTypeOutstandingBalance CaptureType = "OUTSTANDING_BALANCE"
) )
type ProductType string type ProductType string
type ProductCategory string //Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#definition-product_category type ProductCategory string //Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#definition-product_category
const ( const (
ProductTypePhysical ProductType = "PHYSICAL" ProductTypePhysical ProductType = "PHYSICAL"
@ -87,15 +89,15 @@ const (
ProductCategorySoftware ProductCategory = "SOFTWARE" ProductCategorySoftware ProductCategory = "SOFTWARE"
ProductCategorySoftwareComputerAndDataProcessingServices ProductCategory = "COMPUTER_AND_DATA_PROCESSING_SERVICES" ProductCategorySoftwareComputerAndDataProcessingServices ProductCategory = "COMPUTER_AND_DATA_PROCESSING_SERVICES"
ProductCategorySoftwareDigitalGames ProductCategory = "DIGITAL_GAMES" ProductCategorySoftwareDigitalGames ProductCategory = "DIGITAL_GAMES"
ProductCategorySoftwareGameSoftware ProductCategory = "GAME_SOFTWARE" ProductCategorySoftwareGameSoftware ProductCategory = "GAME_SOFTWARE"
ProductCategorySoftwareGames ProductCategory = "GAMES" ProductCategorySoftwareGames ProductCategory = "GAMES"
ProductCategorySoftwareGeneral ProductCategory = "GENERAL" ProductCategorySoftwareGeneral ProductCategory = "GENERAL"
ProductCategorySoftwareGraphicAndCommercialDesign ProductCategory = "GRAPHIC_AND_COMMERCIAL_DESIGN" ProductCategorySoftwareGraphicAndCommercialDesign ProductCategory = "GRAPHIC_AND_COMMERCIAL_DESIGN"
ProductCategorySoftwareOemSoftware ProductCategory = "OEM_SOFTWARE" ProductCategorySoftwareOemSoftware ProductCategory = "OEM_SOFTWARE"
ProductCategorySoftwareOnlineGaming ProductCategory = "ONLINE_GAMING" ProductCategorySoftwareOnlineGaming ProductCategory = "ONLINE_GAMING"
ProductCategorySoftwareOnlineGamingCurrency ProductCategory = "ONLINE_GAMING_CURRENCY" ProductCategorySoftwareOnlineGamingCurrency ProductCategory = "ONLINE_GAMING_CURRENCY"
ProductCategorySoftwareOnlineServices ProductCategory = "ONLINE_SERVICES" ProductCategorySoftwareOnlineServices ProductCategory = "ONLINE_SERVICES"
ProductCategorySoftwareOther ProductCategory = "OTHER" ProductCategorySoftwareOther ProductCategory = "OTHER"
ProductCategorySoftwareServices ProductCategory = "SERVICES" ProductCategorySoftwareServices ProductCategory = "SERVICES"
) )

View File

@ -28,7 +28,7 @@ func ExampleClient_CreateSinglePayout_Venmo() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Set payout item with Venmo wallet // Set payout item with Venmo wallet
payout := paypal.Payout{ payout := paypal.Payout{
SenderBatchHeader: &paypal.SenderBatchHeader{ SenderBatchHeader: &paypal.SenderBatchHeader{
@ -38,9 +38,9 @@ func ExampleClient_CreateSinglePayout_Venmo() {
}, },
Items: []paypal.PayoutItem{ Items: []paypal.PayoutItem{
{ {
RecipientType: "EMAIL", RecipientType: "EMAIL",
RecipientWallet: paypal.VenmoRecipientWallet, RecipientWallet: paypal.VenmoRecipientWallet,
Receiver: "receiver@example.com", Receiver: "receiver@example.com",
Amount: &paypal.AmountPayout{ Amount: &paypal.AmountPayout{
Value: "9.87", Value: "9.87",
Currency: "USD", Currency: "USD",
@ -52,4 +52,4 @@ func ExampleClient_CreateSinglePayout_Venmo() {
} }
c.CreateSinglePayout(payout) c.CreateSinglePayout(payout)
} }

View File

@ -15,7 +15,7 @@ var testSecret = "EBoIiUSkCKeSk49hHSgTem1qnjzzJgRQHDEHvGpzlLEf_nIoJd91xu8rPOBDCd
var testUserID = "https://www.paypal.com/webapps/auth/identity/user/VBqgHcgZwb1PBs69ybjjXfIW86_Hr93aBvF_Rgbh2II" var testUserID = "https://www.paypal.com/webapps/auth/identity/user/VBqgHcgZwb1PBs69ybjjXfIW86_Hr93aBvF_Rgbh2II"
var testCardID = "CARD-54E6956910402550WKGRL6EA" var testCardID = "CARD-54E6956910402550WKGRL6EA"
var testProductId = "" // will be fetched in func TestProduct(t *testing.T) var testProductId = "" // will be fetched in func TestProduct(t *testing.T)
var testBillingPlan = "" // will be fetched in func TestSubscriptionPlans(t *testing.T) var testBillingPlan = "" // will be fetched in func TestSubscriptionPlans(t *testing.T)
func TestGetAccessToken(t *testing.T) { func TestGetAccessToken(t *testing.T) {
@ -386,7 +386,7 @@ func TestSubscription(t *testing.T) {
c.GetAccessToken() c.GetAccessToken()
newSubscription := SubscriptionBase{ newSubscription := SubscriptionBase{
PlanID: testBillingPlan, PlanID: testBillingPlan,
} }
//create new subscription //create new subscription

View File

@ -57,8 +57,6 @@ func (self *Product) GetUpdatePatch() []Patch {
} }
} }
// CreateProduct creates a product // CreateProduct creates a product
// Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#products_create // Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
// Endpoint: POST /v1/catalogs/products // Endpoint: POST /v1/catalogs/products

View File

@ -8,12 +8,12 @@ import (
type ( type (
SubscriptionBase struct { SubscriptionBase struct {
PlanID string `json:"plan_id"` PlanID string `json:"plan_id"`
StartTime *JSONTime `json:"start_time,omitempty"` StartTime *JSONTime `json:"start_time,omitempty"`
Quantity string `json:"quantity,omitempty"` Quantity string `json:"quantity,omitempty"`
ShippingAmount *Money `json:"shipping_amount,omitempty"` ShippingAmount *Money `json:"shipping_amount,omitempty"`
Subscriber *Subscriber `json:"subscriber,omitempty"` Subscriber *Subscriber `json:"subscriber,omitempty"`
AutoRenewal bool `json:"auto_renewal,omitempty"` AutoRenewal bool `json:"auto_renewal,omitempty"`
ApplicationContext *ApplicationContext `json:"application_context,omitempty"` ApplicationContext *ApplicationContext `json:"application_context,omitempty"`
CustomID string `json:"custom_id,omitempty"` CustomID string `json:"custom_id,omitempty"`
} }
@ -67,9 +67,9 @@ type (
} }
CaptureReqeust struct { CaptureReqeust struct {
Note string `json:"note"` Note string `json:"note"`
CaptureType CaptureType `json:"capture_type"` CaptureType CaptureType `json:"capture_type"`
Amount Money `json:"amount"` Amount Money `json:"amount"`
} }
) )
@ -126,7 +126,7 @@ func (c *Client) GetSubscriptionDetails(subscriptionID string) (*SubscriptionDet
// Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate // Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate
// Endpoint: POST /v1/billing/subscriptions/{id}/activate // Endpoint: POST /v1/billing/subscriptions/{id}/activate
func (c *Client) ActivateSubscription(subscriptionId, activateReason string) error { func (c *Client) ActivateSubscription(subscriptionId, activateReason string) error {
req, err := c.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/billing/subscriptions/%s/activate", c.APIBase, subscriptionId), map[string]string{"reason":activateReason}) req, err := c.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/billing/subscriptions/%s/activate", c.APIBase, subscriptionId), map[string]string{"reason": activateReason})
if err != nil { if err != nil {
return err return err
} }

View File

@ -16,7 +16,7 @@ type (
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
BillingCycles []BillingCycle `json:"billing_cycles"` BillingCycles []BillingCycle `json:"billing_cycles"`
PaymentPreferences *PaymentPreferences `json:"payment_preferences"` PaymentPreferences *PaymentPreferences `json:"payment_preferences"`
Taxes *Taxes `json:"taxes"` Taxes *Taxes `json:"taxes"`
QuantitySupported bool `json:"quantity_supported"` //Indicates whether you can subscribe to this plan by providing a quantity for the goods or service. QuantitySupported bool `json:"quantity_supported"` //Indicates whether you can subscribe to this plan by providing a quantity for the goods or service.
} }

View File

@ -116,12 +116,31 @@ const (
FeatureUpdateCustomerDispute string = "UPDATE_CUSTOMER_DISPUTES" FeatureUpdateCustomerDispute string = "UPDATE_CUSTOMER_DISPUTES"
) )
// https://developer.paypal.com/docs/api/payments.payouts-batch/v1/?mark=recipient_type#definition-recipient_type
const (
EmailRecipientType string = "EMAIL" // An unencrypted email — string of up to 127 single-byte characters.
PaypalIdRecipientType string = "PAYPAL_ID" // An encrypted PayPal account number.
PhoneRecipientType string = "PHONE" // An unencrypted phone number.
// Note: The PayPal sandbox doesn't support type PHONE
)
// https://developer.paypal.com/docs/api/payments.payouts-batch/v1/?mark=recipient_wallet#definition-recipient_wallet // https://developer.paypal.com/docs/api/payments.payouts-batch/v1/?mark=recipient_wallet#definition-recipient_wallet
const ( const (
PaypalRecipientWallet string = "PAYPAL" PaypalRecipientWallet string = "PAYPAL"
VenmoRecipientWallet string = "VENMO" VenmoRecipientWallet string = "VENMO"
) )
// Possible value for `batch_status` in GetPayout
//
// https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#definition-batch_status
const (
BatchStatusDenied string = "DENIED"
BatchStatusPending string = "PENDING"
BatchStatusProcessing string = "PROCESSING"
BatchStatusSuccess string = "SUCCESS"
BatchStatusCanceled string = "CANCELED"
)
const ( const (
LinkRelSelf string = "self" LinkRelSelf string = "self"
LinkRelActionURL string = "action_url" LinkRelActionURL string = "action_url"
@ -138,10 +157,10 @@ type (
// Address struct // Address struct
Address struct { Address struct {
Line1 string `json:"line1"` Line1 string `json:"line1,omitempty"`
Line2 string `json:"line2,omitempty"` Line2 string `json:"line2,omitempty"`
City string `json:"city"` City string `json:"city,omitempty"`
CountryCode string `json:"country_code"` CountryCode string `json:"country_code,omitempty"`
PostalCode string `json:"postal_code,omitempty"` PostalCode string `json:"postal_code,omitempty"`
State string `json:"state,omitempty"` State string `json:"state,omitempty"`
Phone string `json:"phone,omitempty"` Phone string `json:"phone,omitempty"`
@ -520,6 +539,7 @@ type (
PurchaseUnit struct { PurchaseUnit struct {
ReferenceID string `json:"reference_id"` ReferenceID string `json:"reference_id"`
Amount *PurchaseUnitAmount `json:"amount,omitempty"` Amount *PurchaseUnitAmount `json:"amount,omitempty"`
Payments *CapturedPayments `json:"payments,omitempty"`
} }
// TaxInfo used for orders. // TaxInfo used for orders.
@ -610,12 +630,13 @@ type (
ExchangeRate *ExchangeRate `json:"exchange_rate,omitempty"` ExchangeRate *ExchangeRate `json:"exchange_rate,omitempty"`
PlatformFees []PlatformFee `json:"platform_fees,omitempty"` PlatformFees []PlatformFee `json:"platform_fees,omitempty"`
} }
// CaptureAmount struct // CaptureAmount struct
CaptureAmount struct { CaptureAmount struct {
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
CustomID string `json:"custom_id,omitempty"` CustomID string `json:"custom_id,omitempty"`
Amount *PurchaseUnitAmount `json:"amount,omitempty"` Amount *PurchaseUnitAmount `json:"amount,omitempty"`
SellerProtection *SellerProtection `json:"seller_protection,omitempty"`
SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"` SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"`
} }
@ -650,6 +671,7 @@ type (
EmailAddress string `json:"email_address,omitempty"` EmailAddress string `json:"email_address,omitempty"`
Phone *PhoneWithType `json:"phone,omitempty"` Phone *PhoneWithType `json:"phone,omitempty"`
PayerID string `json:"payer_id,omitempty"` PayerID string `json:"payer_id,omitempty"`
Address Address `json:"address,omitempty"`
} }
// CaptureOrderResponse is the response for capture order // CaptureOrderResponse is the response for capture order
@ -657,6 +679,7 @@ type (
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Payer *PayerWithNameAndPhone `json:"payer,omitempty"` Payer *PayerWithNameAndPhone `json:"payer,omitempty"`
Address *Address `json:"address,omitempty"`
PurchaseUnits []CapturedPurchaseUnit `json:"purchase_units,omitempty"` PurchaseUnits []CapturedPurchaseUnit `json:"purchase_units,omitempty"`
} }