2015-10-14 07:30:28 +02:00
|
|
|
package paypalsdk
|
|
|
|
|
|
|
|
import (
|
2017-10-21 15:13:24 +02:00
|
|
|
"encoding/json"
|
2015-10-23 04:29:36 +02:00
|
|
|
"fmt"
|
2016-05-16 12:04:23 +02:00
|
|
|
"io"
|
2015-10-23 04:29:36 +02:00
|
|
|
"net/http"
|
2015-11-25 11:30:25 +01:00
|
|
|
"time"
|
2015-10-14 07:30:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-10-23 04:29:36 +02:00
|
|
|
// APIBaseSandBox points to the sandbox (for testing) version of the API
|
|
|
|
APIBaseSandBox = "https://api.sandbox.paypal.com"
|
2015-10-14 07:30:28 +02:00
|
|
|
|
2015-10-23 04:29:36 +02:00
|
|
|
// APIBaseLive points to the live version of the API
|
|
|
|
APIBaseLive = "https://api.paypal.com"
|
2016-09-19 06:39:05 +02:00
|
|
|
|
|
|
|
// RequestNewTokenBeforeExpiresIn is used by SendWithAuth and try to get new Token when it's about to expire
|
2017-07-07 00:52:39 +02:00
|
|
|
RequestNewTokenBeforeExpiresIn = time.Duration(60) * time.Second
|
2015-10-14 07:30:28 +02:00
|
|
|
)
|
|
|
|
|
2016-10-25 21:44:10 +02:00
|
|
|
// Possible values for `no_shipping` in InputFields
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields
|
|
|
|
const (
|
|
|
|
NoShippingDisplay uint = 0
|
|
|
|
NoShippingHide uint = 1
|
|
|
|
NoShippingBuyerAccount uint = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
// Possible values for `address_override` in InputFields
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields
|
|
|
|
const (
|
|
|
|
AddrOverrideFromFile uint = 0
|
|
|
|
AddrOverrideFromCall uint = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
// Possible values for `landing_page_type` in FlowConfig
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-flow_config
|
|
|
|
const (
|
|
|
|
LandingPageTypeBilling string = "Billing"
|
|
|
|
LandingPageTypeLogin string = "Login"
|
|
|
|
)
|
|
|
|
|
2015-10-14 07:30:28 +02:00
|
|
|
type (
|
2017-10-03 05:30:39 +02:00
|
|
|
// JSONTime overrides MarshalJson method to format in ISO8601
|
|
|
|
JSONTime time.Time
|
2017-07-23 07:47:17 +02:00
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Address struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Address struct {
|
|
|
|
Line1 string `json:"line1"`
|
|
|
|
Line2 string `json:"line2,omitempty"`
|
|
|
|
City string `json:"city"`
|
|
|
|
CountryCode string `json:"country_code"`
|
|
|
|
PostalCode string `json:"postal_code,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
Phone string `json:"phone,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-08-24 12:22:46 +02:00
|
|
|
// AgreementDetails struct
|
|
|
|
AgreementDetails struct {
|
|
|
|
OutstandingBalance AmountPayout `json:"outstanding_balance"`
|
2017-08-24 17:03:34 +02:00
|
|
|
CyclesRemaining int `json:"cycles_remaining,string"`
|
|
|
|
CyclesCompleted int `json:"cycles_completed,string"`
|
2017-08-24 12:22:46 +02:00
|
|
|
NextBillingDate time.Time `json:"next_billing_date"`
|
|
|
|
LastPaymentDate time.Time `json:"last_payment_date"`
|
|
|
|
LastPaymentAmount AmountPayout `json:"last_payment_amount"`
|
|
|
|
FinalPaymentDate time.Time `json:"final_payment_date"`
|
2017-08-24 17:03:34 +02:00
|
|
|
FailedPaymentCount int `json:"failed_payment_count,string"`
|
2017-08-24 12:22:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Amount struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Amount struct {
|
2017-09-26 17:26:02 +02:00
|
|
|
Currency string `json:"currency"`
|
|
|
|
Total string `json:"total"`
|
|
|
|
Details Details `json:"details,omitempty"`
|
2015-10-23 04:29:36 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// AmountPayout struct
|
2016-02-17 05:10:49 +01:00
|
|
|
AmountPayout struct {
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Authorization struct
|
2015-12-01 05:35:25 +01:00
|
|
|
Authorization struct {
|
|
|
|
Amount *Amount `json:"amount,omitempty"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
ParentPayment string `json:"parent_payment,omitempty"`
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
ValidUntil *time.Time `json:"valid_until,omitempty"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links,omitempty"`
|
2015-12-01 05:35:25 +01:00
|
|
|
ClearingTime string `json:"clearing_time,omitempty"`
|
|
|
|
ProtectionEligibility string `json:"protection_eligibility,omitempty"`
|
|
|
|
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// BatchHeader struct
|
2016-02-17 05:10:49 +01:00
|
|
|
BatchHeader struct {
|
|
|
|
Amount *AmountPayout `json:"amount,omitempty"`
|
|
|
|
Fees *AmountPayout `json:"fees,omitempty"`
|
|
|
|
PayoutBatchID string `json:"payout_batch_id,omitempty"`
|
|
|
|
BatchStatus string `json:"batch_status,omitempty"`
|
|
|
|
TimeCreated *time.Time `json:"time_created,omitempty"`
|
|
|
|
TimeCompleted *time.Time `json:"time_completed,omitempty"`
|
|
|
|
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-07-23 07:47:17 +02:00
|
|
|
// BillingAgreement struct
|
|
|
|
BillingAgreement struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
2017-10-03 05:30:39 +02:00
|
|
|
StartDate JSONTime `json:"start_date,omitempty"`
|
2017-07-23 07:47:17 +02:00
|
|
|
Plan BillingPlan `json:"plan,omitempty"`
|
|
|
|
Payer Payer `json:"payer,omitempty"`
|
|
|
|
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-07-20 11:07:11 +02:00
|
|
|
// BillingPlan struct
|
|
|
|
BillingPlan struct {
|
2017-07-23 07:47:17 +02:00
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"`
|
|
|
|
MerchantPreferences *MerchantPreferences `json:"merchant_preferences,omitempty"`
|
2017-07-20 11:07:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Capture struct
|
2015-12-01 05:35:25 +01:00
|
|
|
Capture struct {
|
|
|
|
Amount *Amount `json:"amount,omitempty"`
|
|
|
|
IsFinalCapture bool `json:"is_final_capture"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
ParentPayment string `json:"parent_payment,omitempty"`
|
|
|
|
ID string `json:"id,omitempty"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links,omitempty"`
|
2015-12-01 05:35:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-20 11:07:11 +02:00
|
|
|
// ChargeModel struct
|
|
|
|
ChargeModel struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Amount AmountPayout `json:"amount,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-12-17 08:50:25 +01:00
|
|
|
// Client represents a Paypal REST API Client
|
|
|
|
Client struct {
|
2017-07-20 11:07:11 +02:00
|
|
|
Client *http.Client
|
|
|
|
ClientID string
|
|
|
|
Secret string
|
|
|
|
APIBase string
|
|
|
|
Log io.Writer // If user set log file name all requests will be logged there
|
|
|
|
Token *TokenResponse
|
2017-07-07 00:52:39 +02:00
|
|
|
tokenExpiresAt time.Time
|
2015-11-25 11:30:25 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// CreditCard struct
|
2015-11-25 11:30:25 +01:00
|
|
|
CreditCard struct {
|
2017-05-25 23:16:33 +02:00
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
PayerID string `json:"payer_id,omitempty"`
|
2017-05-25 23:27:19 +02:00
|
|
|
ExternalCustomerID string `json:"external_customer_id,omitempty"`
|
2017-05-25 23:16:33 +02:00
|
|
|
Number string `json:"number"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
ExpireMonth string `json:"expire_month"`
|
|
|
|
ExpireYear string `json:"expire_year"`
|
|
|
|
CVV2 string `json:"cvv2,omitempty"`
|
|
|
|
FirstName string `json:"first_name,omitempty"`
|
|
|
|
LastName string `json:"last_name,omitempty"`
|
|
|
|
BillingAddress *Address `json:"billing_address,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
ValidUntil string `json:"valid_until,omitempty"`
|
2015-11-25 11:30:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 06:55:00 +01:00
|
|
|
// CreditCards GET /v1/vault/credit-cards
|
|
|
|
CreditCards struct {
|
|
|
|
Items []CreditCard `json:"items"`
|
|
|
|
Links []Link `json:"links"`
|
|
|
|
TotalItems int `json:"total_items"`
|
|
|
|
TotalPages int `json:"total_pages"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// CreditCardToken struct
|
2015-11-25 11:30:25 +01:00
|
|
|
CreditCardToken struct {
|
|
|
|
CreditCardID string `json:"credit_card_id"`
|
|
|
|
PayerID string `json:"payer_id,omitempty"`
|
|
|
|
Last4 string `json:"last4,omitempty"`
|
|
|
|
ExpireYear string `json:"expire_year,omitempty"`
|
|
|
|
ExpireMonth string `json:"expire_month,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-12-19 06:55:00 +01:00
|
|
|
// CreditCardsFilter struct
|
|
|
|
CreditCardsFilter struct {
|
|
|
|
PageSize int
|
|
|
|
Page int
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreditCardField PATCH /v1/vault/credit-cards/credit_card_id
|
|
|
|
CreditCardField struct {
|
|
|
|
Operation string `json:"op"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Currency struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Currency struct {
|
|
|
|
Currency string `json:"currency,omitempty"`
|
|
|
|
Value string `json:"value,omitempty"`
|
2015-10-23 04:29:36 +02:00
|
|
|
}
|
2015-10-14 07:30:28 +02:00
|
|
|
|
2017-09-26 17:26:02 +02:00
|
|
|
// Details structure used in Amount structures as optional value
|
|
|
|
Details 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"`
|
|
|
|
}
|
|
|
|
|
2017-10-26 02:43:41 +02:00
|
|
|
ErrorResponseDetail struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Issue string `json:"issue"`
|
|
|
|
Links []Link `json:"link"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// ErrorResponse https://developer.paypal.com/docs/api/errors/
|
2015-10-23 04:29:36 +02:00
|
|
|
ErrorResponse struct {
|
2017-10-26 02:43:41 +02:00
|
|
|
Response *http.Response `json:"-"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
DebugID string `json:"debug_id"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
InformationLink string `json:"information_link"`
|
|
|
|
Details []ErrorResponseDetail `json:"details"`
|
2015-10-23 04:29:36 +02:00
|
|
|
}
|
2015-10-16 12:00:57 +02:00
|
|
|
|
2017-08-24 12:22:46 +02:00
|
|
|
// ExecuteAgreementResponse struct
|
|
|
|
ExecuteAgreementResponse struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
State string `json:"state"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Payer Payer `json:"payer"`
|
|
|
|
Plan BillingPlan `json:"plan"`
|
|
|
|
StartDate time.Time `json:"start_date"`
|
|
|
|
ShippingAddress ShippingAddress `json:"shipping_address"`
|
|
|
|
AgreementDetails AgreementDetails `json:"agreement_details"`
|
|
|
|
Links []Link `json:"links"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// ExecuteResponse struct
|
2015-12-17 08:50:25 +01:00
|
|
|
ExecuteResponse struct {
|
2016-08-18 18:53:22 +02:00
|
|
|
ID string `json:"id"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links"`
|
2016-08-18 18:53:22 +02:00
|
|
|
State string `json:"state"`
|
|
|
|
Transactions []Transaction `json:"transactions,omitempty"`
|
2015-11-16 06:11:27 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// FundingInstrument struct
|
2015-12-17 08:50:25 +01:00
|
|
|
FundingInstrument struct {
|
|
|
|
CreditCard *CreditCard `json:"credit_card,omitempty"`
|
|
|
|
CreditCardToken *CreditCardToken `json:"credit_card_token,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Item struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Item struct {
|
2017-01-27 15:00:29 +01:00
|
|
|
Quantity int `json:"quantity"`
|
2015-12-17 08:50:25 +01:00
|
|
|
Name string `json:"name"`
|
|
|
|
Price string `json:"price"`
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
SKU string `json:"sku,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Tax string `json:"tax,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ItemList struct
|
|
|
|
ItemList struct {
|
|
|
|
Items []Item `json:"items,omitempty"`
|
|
|
|
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-12-19 06:55:00 +01:00
|
|
|
// Link struct
|
|
|
|
Link struct {
|
2015-12-17 08:50:25 +01:00
|
|
|
Href string `json:"href"`
|
2016-02-17 05:10:49 +01:00
|
|
|
Rel string `json:"rel,omitempty"`
|
|
|
|
Method string `json:"method,omitempty"`
|
|
|
|
Enctype string `json:"enctype,omitempty"`
|
2015-12-17 08:50:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-20 11:07:11 +02:00
|
|
|
// MerchantPreferences struct
|
|
|
|
MerchantPreferences struct {
|
2017-08-24 08:08:31 +02:00
|
|
|
SetupFee *AmountPayout `json:"setup_fee,omitempty"`
|
2017-10-03 05:30:39 +02:00
|
|
|
ReturnURL string `json:"return_url,omitempty"`
|
|
|
|
CancelURL string `json:"cancel_url,omitempty"`
|
2017-08-24 08:08:31 +02:00
|
|
|
AutoBillAmount string `json:"auto_bill_amount,omitempty"`
|
|
|
|
InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"`
|
|
|
|
MaxFailAttempts string `json:"max_fail_attempts,omitempty"`
|
2017-07-20 11:07:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Order struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Order struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
Amount *Amount `json:"amount,omitempty"`
|
|
|
|
PendingReason string `json:"pending_reason,omitempty"`
|
|
|
|
ParentPayment string `json:"parent_payment,omitempty"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links,omitempty"`
|
2015-12-17 08:50:25 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Payer struct
|
2015-11-25 11:30:25 +01:00
|
|
|
Payer struct {
|
|
|
|
PaymentMethod string `json:"payment_method"`
|
|
|
|
FundingInstruments []FundingInstrument `json:"funding_instruments,omitempty"`
|
|
|
|
PayerInfo *PayerInfo `json:"payer_info,omitempty"`
|
|
|
|
Status string `json:"payer_status,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// PayerInfo struct
|
2015-11-25 11:30:25 +01:00
|
|
|
PayerInfo struct {
|
|
|
|
Email string `json:"email,omitempty"`
|
|
|
|
FirstName string `json:"first_name,omitempty"`
|
|
|
|
LastName string `json:"last_name,omitempty"`
|
|
|
|
PayerID string `json:"payer_id,omitempty"`
|
|
|
|
Phone string `json:"phone,omitempty"`
|
|
|
|
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
|
|
|
TaxIDType string `json:"tax_id_type,omitempty"`
|
|
|
|
TaxID string `json:"tax_id,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Payment struct
|
2015-11-25 11:30:25 +01:00
|
|
|
Payment struct {
|
|
|
|
Intent string `json:"intent"`
|
|
|
|
Payer *Payer `json:"payer"`
|
|
|
|
Transactions []Transaction `json:"transactions"`
|
|
|
|
RedirectURLs *RedirectURLs `json:"redirect_urls,omitempty"`
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
|
|
|
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-07-20 11:07:11 +02:00
|
|
|
// PaymentDefinition struct
|
|
|
|
PaymentDefinition struct {
|
2017-07-22 13:48:16 +02:00
|
|
|
ID string `json:"id,omitempty"`
|
2017-07-20 11:07:11 +02:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Frequency string `json:"frequency,omitempty"`
|
|
|
|
FrequencyInterval string `json:"frequency_interval,omitempty"`
|
|
|
|
Amount AmountPayout `json:"amount,omitempty"`
|
|
|
|
Cycles string `json:"cycles,omitempty"`
|
|
|
|
ChargeModels []ChargeModel `json:"charge_models,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-12-17 08:50:25 +01:00
|
|
|
// PaymentResponse structure
|
|
|
|
PaymentResponse struct {
|
2016-12-19 06:55:00 +01:00
|
|
|
ID string `json:"id"`
|
|
|
|
Links []Link `json:"links"`
|
2015-12-17 08:50:25 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Payout struct
|
2016-02-17 05:10:49 +01:00
|
|
|
Payout struct {
|
|
|
|
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header"`
|
|
|
|
Items []PayoutItem `json:"items"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// PayoutItem struct
|
2016-02-17 05:10:49 +01:00
|
|
|
PayoutItem struct {
|
|
|
|
RecipientType string `json:"recipient_type"`
|
|
|
|
Receiver string `json:"receiver"`
|
|
|
|
Amount *AmountPayout `json:"amount"`
|
|
|
|
Note string `json:"note,omitempty"`
|
|
|
|
SenderItemID string `json:"sender_item_id,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// PayoutItemResponse struct
|
2016-02-17 05:10:49 +01:00
|
|
|
PayoutItemResponse struct {
|
2017-11-08 00:48:19 +01:00
|
|
|
PayoutItemID string `json:"payout_item_id"`
|
|
|
|
TransactionID string `json:"transaction_id"`
|
|
|
|
TransactionStatus string `json:"transaction_status"`
|
|
|
|
PayoutBatchID string `json:"payout_batch_id,omitempty"`
|
|
|
|
PayoutItemFee *AmountPayout `json:"payout_item_fee,omitempty"`
|
|
|
|
PayoutItem *PayoutItem `json:"payout_item"`
|
|
|
|
TimeProcessed *time.Time `json:"time_processed,omitempty"`
|
|
|
|
Links []Link `json:"links"`
|
|
|
|
Error *ErrorResponse `json:"errors,omitempty"`
|
2016-02-17 05:10:49 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// PayoutResponse struct
|
2016-02-17 05:10:49 +01:00
|
|
|
PayoutResponse struct {
|
|
|
|
BatchHeader *BatchHeader `json:"batch_header"`
|
|
|
|
Items []PayoutItemResponse `json:"items"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links"`
|
2016-02-17 05:10:49 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// RedirectURLs struct
|
2015-12-17 08:50:25 +01:00
|
|
|
RedirectURLs struct {
|
|
|
|
ReturnURL string `json:"return_url,omitempty"`
|
|
|
|
CancelURL string `json:"cancel_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Refund struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Refund struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Amount *Amount `json:"amount,omitempty"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
CaptureID string `json:"capture_id,omitempty"`
|
|
|
|
ParentPayment string `json:"parent_payment,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
2015-11-16 06:11:27 +01:00
|
|
|
}
|
2015-12-17 04:56:49 +01:00
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Related struct
|
2016-08-18 18:53:22 +02:00
|
|
|
Related struct {
|
|
|
|
Sale *Sale `json:"sale,omitempty"`
|
|
|
|
Authorization *Authorization `json:"authorization,omitempty"`
|
|
|
|
Order *Order `json:"order,omitempty"`
|
|
|
|
Capture *Capture `json:"capture,omitempty"`
|
|
|
|
Refund *Refund `json:"refund,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Sale struct
|
2015-12-17 04:56:49 +01:00
|
|
|
Sale struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Amount *Amount `json:"amount,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
ParentPayment string `json:"parent_payment,omitempty"`
|
|
|
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
|
|
|
PaymentMode string `json:"payment_mode,omitempty"`
|
|
|
|
PendingReason string `json:"pending_reason,omitempty"`
|
|
|
|
ReasonCode string `json:"reason_code,omitempty"`
|
|
|
|
ClearingTime string `json:"clearing_time,omitempty"`
|
|
|
|
ProtectionEligibility string `json:"protection_eligibility,omitempty"`
|
|
|
|
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
|
2016-12-19 06:55:00 +01:00
|
|
|
Links []Link `json:"links,omitempty"`
|
2015-12-17 04:56:49 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// SenderBatchHeader struct
|
2016-02-17 05:10:49 +01:00
|
|
|
SenderBatchHeader struct {
|
2017-10-02 08:12:42 +02:00
|
|
|
EmailSubject string `json:"email_subject"`
|
|
|
|
SenderBatchID string `json:"sender_batch_id,omitempty"`
|
2016-02-17 05:10:49 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// ShippingAddress struct
|
2015-12-17 08:50:25 +01:00
|
|
|
ShippingAddress struct {
|
|
|
|
RecipientName string `json:"recipient_name,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Line1 string `json:"line1"`
|
|
|
|
Line2 string `json:"line2,omitempty"`
|
|
|
|
City string `json:"city"`
|
|
|
|
CountryCode string `json:"country_code"`
|
|
|
|
PostalCode string `json:"postal_code,omitempty"`
|
|
|
|
State string `json:"state,omitempty"`
|
|
|
|
Phone string `json:"phone,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-10-21 15:13:24 +02:00
|
|
|
expirationTime int64
|
|
|
|
|
2015-12-17 08:50:25 +01:00
|
|
|
// TokenResponse is for API response for the /oauth2/token endpoint
|
|
|
|
TokenResponse struct {
|
2017-10-21 15:13:24 +02:00
|
|
|
RefreshToken string `json:"refresh_token"`
|
|
|
|
Token string `json:"access_token"`
|
|
|
|
Type string `json:"token_type"`
|
|
|
|
ExpiresIn expirationTime `json:"expires_in"`
|
2015-12-17 08:50:25 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// Transaction struct
|
2015-12-17 08:50:25 +01:00
|
|
|
Transaction struct {
|
2016-08-18 18:53:22 +02:00
|
|
|
Amount *Amount `json:"amount"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
ItemList *ItemList `json:"item_list,omitempty"`
|
|
|
|
InvoiceNumber string `json:"invoice_number,omitempty"`
|
|
|
|
Custom string `json:"custom,omitempty"`
|
|
|
|
SoftDescriptor string `json:"soft_descriptor,omitempty"`
|
|
|
|
RelatedResources []Related `json:"related_resources,omitempty"`
|
2015-12-17 04:56:49 +01:00
|
|
|
}
|
2016-01-20 05:17:19 +01:00
|
|
|
|
2016-10-24 06:36:23 +02:00
|
|
|
// UserInfo struct
|
2016-01-20 05:17:19 +01:00
|
|
|
UserInfo struct {
|
|
|
|
ID string `json:"user_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
GivenName string `json:"given_name"`
|
|
|
|
FamilyName string `json:"family_name"`
|
|
|
|
Email string `json:"email"`
|
2017-10-21 15:14:27 +02:00
|
|
|
Verified bool `json:"verified,omitempty,string"`
|
2016-01-20 05:17:19 +01:00
|
|
|
Gender string `json:"gender,omitempty"`
|
|
|
|
BirthDate string `json:"birthdate,omitempty"`
|
|
|
|
ZoneInfo string `json:"zoneinfo,omitempty"`
|
|
|
|
Locale string `json:"locale,omitempty"`
|
|
|
|
Phone string `json:"phone_number,omitempty"`
|
|
|
|
Address *Address `json:"address,omitempty"`
|
2017-10-21 15:14:27 +02:00
|
|
|
VerifiedAccount bool `json:"verified_account,omitempty,string"`
|
2016-01-20 05:17:19 +01:00
|
|
|
AccountType string `json:"account_type,omitempty"`
|
|
|
|
AgeRange string `json:"age_range,omitempty"`
|
|
|
|
PayerID string `json:"payer_id,omitempty"`
|
|
|
|
}
|
2016-10-25 21:44:10 +02:00
|
|
|
|
|
|
|
// WebProfile represents the configuration of the payment web payment experience
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/
|
|
|
|
WebProfile struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Presentation Presentation `json:"presentation,omitempty"`
|
|
|
|
InputFields InputFields `json:"input_fields,omitempty"`
|
|
|
|
FlowConfig FlowConfig `json:"flow_config,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Presentation represents the branding and locale that a customer sees on
|
|
|
|
// redirect payments
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-presentation
|
|
|
|
Presentation struct {
|
|
|
|
BrandName string `json:"brand_name,omitempty"`
|
|
|
|
LogoImage string `json:"logo_image,omitempty"`
|
|
|
|
LocaleCode string `json:"locale_code,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// InputFields represents the fields that are displayed to a customer on
|
|
|
|
// redirect payments
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields
|
|
|
|
InputFields struct {
|
|
|
|
AllowNote bool `json:"allow_note,omitempty"`
|
|
|
|
NoShipping uint `json:"no_shipping,omitempty"`
|
|
|
|
AddressOverride uint `json:"address_override,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FlowConfig represents the general behaviour of redirect payment pages
|
|
|
|
//
|
|
|
|
// https://developer.paypal.com/docs/api/payment-experience/#definition-flow_config
|
|
|
|
FlowConfig struct {
|
|
|
|
LandingPageType string `json:"landing_page_type,omitempty"`
|
|
|
|
BankTXNPendingURL string `json:"bank_txn_pending_url,omitempty"`
|
|
|
|
UserAction string `json:"user_action,omitempty"`
|
|
|
|
}
|
2015-10-14 07:30:28 +02:00
|
|
|
)
|
2015-10-15 07:43:50 +02:00
|
|
|
|
|
|
|
// Error method implementation for ErrorResponse struct
|
|
|
|
func (r *ErrorResponse) Error() string {
|
2016-10-24 06:36:23 +02:00
|
|
|
return fmt.Sprintf("%v %v: %d %s", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message)
|
2015-10-15 07:43:50 +02:00
|
|
|
}
|
2017-07-23 07:47:17 +02:00
|
|
|
|
2017-10-03 05:30:39 +02:00
|
|
|
// MarshalJSON for JSONTime
|
|
|
|
func (t JSONTime) MarshalJSON() ([]byte, error) {
|
2017-07-23 07:47:17 +02:00
|
|
|
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
|
|
|
|
return []byte(stamp), nil
|
|
|
|
}
|
2017-10-21 15:13:24 +02:00
|
|
|
|
|
|
|
func (e *expirationTime) UnmarshalJSON(b []byte) error {
|
|
|
|
var n json.Number
|
|
|
|
err := json.Unmarshal(b, &n)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
i, err := n.Int64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*e = expirationTime(i)
|
|
|
|
return nil
|
|
|
|
}
|