github.com/plutov/paypal/v4@v4.7.1/types.go (about) 1 package paypal 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 "net/http" 8 "strings" 9 "sync" 10 "time" 11 ) 12 13 const ( 14 // APIBaseSandBox points to the sandbox (for testing) version of the API 15 APIBaseSandBox = "https://api.sandbox.paypal.com" 16 17 // APIBaseLive points to the live version of the API 18 APIBaseLive = "https://api.paypal.com" 19 20 // RequestNewTokenBeforeExpiresIn is used by SendWithAuth and try to get new Token when it's about to expire 21 RequestNewTokenBeforeExpiresIn = time.Duration(60) * time.Second 22 ) 23 24 // Possible values for `no_shipping` in InputFields 25 // 26 // https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields 27 const ( 28 NoShippingDisplay uint = 0 29 NoShippingHide uint = 1 30 NoShippingBuyerAccount uint = 2 31 ) 32 33 // Possible values for `address_override` in InputFields 34 // 35 // https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields 36 const ( 37 AddrOverrideFromFile uint = 0 38 AddrOverrideFromCall uint = 1 39 ) 40 41 // Possible values for `landing_page_type` in FlowConfig 42 // 43 // https://developer.paypal.com/docs/api/payment-experience/#definition-flow_config 44 const ( 45 LandingPageTypeBilling string = "Billing" 46 LandingPageTypeLogin string = "Login" 47 ) 48 49 // Possible value for `allowed_payment_method` in PaymentOptions 50 // 51 // https://developer.paypal.com/docs/api/payments/#definition-payment_options 52 const ( 53 AllowedPaymentUnrestricted string = "UNRESTRICTED" 54 AllowedPaymentInstantFundingSource string = "INSTANT_FUNDING_SOURCE" 55 AllowedPaymentImmediatePay string = "IMMEDIATE_PAY" 56 ) 57 58 // Possible value for `intent` in CreateOrder 59 // 60 // https://developer.paypal.com/docs/api/orders/v2/#orders_create 61 const ( 62 OrderIntentCapture string = "CAPTURE" 63 OrderIntentAuthorize string = "AUTHORIZE" 64 ) 65 66 // Possible value for `status` in GetOrder 67 // 68 // https://developer.paypal.com/docs/api/orders/v2/#orders-get-response 69 const ( 70 OrderStatusCreated string = "CREATED" 71 OrderStatusSaved string = "SAVED" 72 OrderStatusApproved string = "APPROVED" 73 OrderStatusVoided string = "VOIDED" 74 OrderStatusCompleted string = "COMPLETED" 75 ) 76 77 // Possible values for `category` in Item 78 // 79 // https://developer.paypal.com/docs/api/orders/v2/#definition-item 80 const ( 81 ItemCategoryDigitalGood string = "DIGITAL_GOODS" 82 ItemCategoryPhysicalGood string = "PHYSICAL_GOODS" 83 ) 84 85 // Possible values for `shipping_preference` in ApplicationContext 86 // 87 // https://developer.paypal.com/docs/api/orders/v2/#definition-application_context 88 89 const ( 90 EventCheckoutOrderApproved string = "CHECKOUT.ORDER.APPROVED" 91 EventPaymentCaptureCompleted string = "PAYMENT.CAPTURE.COMPLETED" 92 EventPaymentCaptureDenied string = "PAYMENT.CAPTURE.DENIED" 93 EventPaymentCaptureRefunded string = "PAYMENT.CAPTURE.REFUNDED" 94 EventMerchantOnboardingCompleted string = "MERCHANT.ONBOARDING.COMPLETED" 95 EventMerchantPartnerConsentRevoked string = "MERCHANT.PARTNER-CONSENT.REVOKED" 96 ) 97 98 const ( 99 OperationAPIIntegration string = "API_INTEGRATION" 100 ProductExpressCheckout string = "EXPRESS_CHECKOUT" 101 IntegrationMethodPayPal string = "PAYPAL" 102 IntegrationTypeThirdParty string = "THIRD_PARTY" 103 ConsentShareData string = "SHARE_DATA_CONSENT" 104 ) 105 106 const ( 107 FeaturePayment string = "PAYMENT" 108 FeatureRefund string = "REFUND" 109 FeatureFuturePayment string = "FUTURE_PAYMENT" 110 FeatureDirectPayment string = "DIRECT_PAYMENT" 111 FeaturePartnerFee string = "PARTNER_FEE" 112 FeatureDelayFunds string = "DELAY_FUNDS_DISBURSEMENT" 113 FeatureReadSellerDispute string = "READ_SELLER_DISPUTE" 114 FeatureUpdateSellerDispute string = "UPDATE_SELLER_DISPUTE" 115 FeatureDisputeReadBuyer string = "DISPUTE_READ_BUYER" 116 FeatureUpdateCustomerDispute string = "UPDATE_CUSTOMER_DISPUTES" 117 ) 118 119 // https://developer.paypal.com/docs/api/payments.payouts-batch/v1/?mark=recipient_type#definition-recipient_type 120 const ( 121 EmailRecipientType string = "EMAIL" // An unencrypted email — string of up to 127 single-byte characters. 122 PaypalIdRecipientType string = "PAYPAL_ID" // An encrypted PayPal account number. 123 PhoneRecipientType string = "PHONE" // An unencrypted phone number. 124 // Note: The PayPal sandbox doesn't support type PHONE 125 ) 126 127 // https://developer.paypal.com/docs/api/payments.payouts-batch/v1/?mark=recipient_wallet#definition-recipient_wallet 128 const ( 129 PaypalRecipientWallet string = "PAYPAL" 130 VenmoRecipientWallet string = "VENMO" 131 ) 132 133 // Possible value for `batch_status` in GetPayout 134 // 135 // https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#definition-batch_status 136 const ( 137 BatchStatusDenied string = "DENIED" 138 BatchStatusPending string = "PENDING" 139 BatchStatusProcessing string = "PROCESSING" 140 BatchStatusSuccess string = "SUCCESS" 141 BatchStatusCanceled string = "CANCELED" 142 ) 143 144 const ( 145 LinkRelSelf string = "self" 146 LinkRelActionURL string = "action_url" 147 ) 148 149 const ( 150 AncorTypeApplication string = "APPLICATION" 151 AncorTypeAccount string = "ACCOUNT" 152 ) 153 154 type ( 155 // JSONTime overrides MarshalJson method to format in ISO8601 156 JSONTime time.Time 157 158 // Address struct 159 Address struct { 160 Line1 string `json:"line1,omitempty"` 161 Line2 string `json:"line2,omitempty"` 162 City string `json:"city,omitempty"` 163 CountryCode string `json:"country_code,omitempty"` 164 PostalCode string `json:"postal_code,omitempty"` 165 State string `json:"state,omitempty"` 166 Phone string `json:"phone,omitempty"` 167 } 168 169 // AgreementDetails struct 170 AgreementDetails struct { 171 OutstandingBalance AmountPayout `json:"outstanding_balance"` 172 CyclesRemaining int `json:"cycles_remaining,string"` 173 CyclesCompleted int `json:"cycles_completed,string"` 174 NextBillingDate time.Time `json:"next_billing_date"` 175 LastPaymentDate time.Time `json:"last_payment_date"` 176 LastPaymentAmount AmountPayout `json:"last_payment_amount"` 177 FinalPaymentDate time.Time `json:"final_payment_date"` 178 FailedPaymentCount int `json:"failed_payment_count,string"` 179 } 180 181 // Amount struct 182 Amount struct { 183 Currency string `json:"currency"` 184 Total string `json:"total"` 185 Details Details `json:"details,omitempty"` 186 } 187 188 // AmountPayout struct 189 AmountPayout struct { 190 Currency string `json:"currency"` 191 Value string `json:"value"` 192 } 193 194 // ApplicationContext struct 195 //Doc: https://developer.paypal.com/docs/api/orders/v2/#definition-application_context 196 ApplicationContext struct { 197 BrandName string `json:"brand_name,omitempty"` 198 Locale string `json:"locale,omitempty"` 199 ShippingPreference ShippingPreference `json:"shipping_preference,omitempty"` 200 UserAction UserAction `json:"user_action,omitempty"` 201 PaymentMethod PaymentMethod `json:"payment_method,omitempty"` 202 LandingPage string `json:"landing_page,omitempty"` 203 ReturnURL string `json:"return_url,omitempty"` 204 CancelURL string `json:"cancel_url,omitempty"` 205 } 206 207 // Invoicing relates structures 208 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-next-invoice-number 209 InvoiceNumber struct { 210 InvoiceNumberValue string `json:"invoice_number"` 211 } 212 213 // used in InvoiceAmountWithBreakdown 214 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-custom_amount 215 CustomAmount struct { 216 Label string `json:"label"` 217 Amount Money `json:"amount,omitempty"` 218 } 219 // Used in AggregatedDiscount 220 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-discount 221 InvoicingDiscount struct { 222 DiscountAmount Money `json:"amount,omitempty"` 223 Percent string `json:"percent,omitempty"` 224 } 225 // Used in InvoiceAmountWithBreakdown 226 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-aggregated_discount 227 AggregatedDiscount struct { 228 InvoiceDiscount InvoicingDiscount `json:"invoice_discount,omitempty"` 229 ItemDiscount *Money `json:"item_discount,omitempty"` 230 } 231 232 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-tax 233 InvoiceTax struct { 234 Name string `json:"name,omitempty"` 235 Percent string `json:"percent,omitempty"` 236 ID string `json:"id,omitempty"` // not mentioned here, but is still returned in response payload, when invoice is requested by ID. 237 Amount Money `json:"amount,omitempty"` 238 } 239 // Used in InvoiceAmountWithBreakdown struct 240 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-shipping_cost 241 InvoiceShippingCost struct { 242 Amount Money `json:"amount,omitempty"` 243 Tax InvoiceTax `json:"tax,omitempty"` 244 } 245 246 // Used in AmountSummaryDetail 247 // Doc: https://developer.paypal.com/docs/api/payments/v2/#definition-nrp-nrr_attributes 248 InvoiceAmountWithBreakdown struct { 249 Custom CustomAmount `json:"custom,omitempty"` // The custom amount to apply to an invoice. 250 Discount AggregatedDiscount `json:"discount,omitempty"` 251 ItemTotal Money `json:"item_total,omitempty"` // The subtotal for all items. 252 Shipping InvoiceShippingCost `json:"shipping,omitempty"` // The shipping fee for all items. Includes tax on shipping. 253 TaxTotal Money `json:"tax_total,omitempty"` 254 } 255 256 // Invoice AmountSummary 257 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-amount_summary_detail 258 AmountSummaryDetail struct { 259 Breakdown InvoiceAmountWithBreakdown `json:"breakdown,omitempty"` 260 Currency string `json:"currency_code,omitempty"` 261 Value string `json:"value,omitempty"` 262 } 263 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-partial_payment 264 InvoicePartialPayment struct { 265 AllowPartialPayment bool `json:"allow_partial_payment,omitempty"` 266 MinimumAmountDue Money `json:"minimum_amount_due,omitempty"` // Valid only when allow_partial_payment is true. 267 } 268 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-configuration 269 InvoiceConfiguration struct { 270 AllowTip bool `json:"allow_tip,omitempty"` 271 PartialPayment InvoicePartialPayment `json:"partial_payment,omitempty"` 272 TaxCalculatedAfterDiscount bool `json:"tax_calculated_after_discount,omitempty"` 273 TaxInclusive bool `json:"tax_inclusive,omitempty"` 274 TemplateId string `json:"template_id,omitempty"` 275 } 276 // used in InvoiceDetail structure 277 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-file_reference 278 InvoiceFileReference struct { 279 ContentType string `json:"content_type,omitempty"` 280 CreateTime string `json:"create_time,omitempty"` 281 ID string `json:"id,omitempty"` 282 URL string `json:"reference_url,omitempty"` 283 Size string `json:"size,omitempty"` 284 } 285 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-metadata 286 InvoiceAuditMetadata struct { 287 CreateTime string `json:"create_time,omitempty"` 288 CreatedBy string `json:"created_by,omitempty"` 289 LastUpdateTime string `json:"last_update_time,omitempty"` 290 LastUpdatedBy string `json:"last_updated_by,omitempty"` 291 CancelTime string `json:"cancel_time,omitempty"` 292 CancellledTimeBy string `json:"cancelled_by,omitempty"` 293 CreatedByFlow string `json:"created_by_flow,omitempty"` 294 FirstSentTime string `json:"first_sent_time,omitempty"` 295 InvoicerViewUrl string `json:"invoicer_view_url,omitempty"` 296 LastSentBy string `json:"last_sent_by,omitempty"` 297 LastSentTime string `json:"last_sent_time,omitempty"` 298 RecipientViewUrl string `json:"recipient_view_url,omitempty"` 299 } 300 // used in InvoiceDetail struct 301 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoice_payment_term 302 InvoicePaymentTerm struct { 303 TermType string `json:"term_type,omitempty"` 304 DueDate string `json:"due_date,omitempty"` 305 } 306 307 // used in Invoice struct 308 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoice_detail 309 InvoiceDetail struct { 310 CurrencyCode string `json:"currency_code"` // required, hence omitempty not used 311 Attachments []InvoiceFileReference `json:"attachments,omitempty"` 312 Memo string `json:"memo,omitempty"` 313 Note string `json:"note,omitempty"` 314 Reference string `json:"reference,omitempty"` 315 TermsAndConditions string `json:"terms_and_conditions,omitempty"` 316 InvoiceDate string `json:"invoice_date,omitempty"` 317 InvoiceNumber string `json:"invoice_number,omitempty"` 318 Metadata InvoiceAuditMetadata `json:"metadata,omitempty"` // The audit metadata. 319 PaymentTerm InvoicePaymentTerm `json:"payment_term,omitempty"` // payment due date for the invoice. Value is either but not both term_type or due_date. 320 } 321 322 // used in InvoicerInfo struct 323 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-phone_detail 324 InvoicerPhoneDetail struct { 325 CountryCode string `json:"country_code"` 326 NationalNumber string `json:"national_number"` 327 ExtensionNumber string `json:"extension_number,omitempty"` 328 PhoneType string `json:"phone_type,omitempty"` 329 } 330 331 // used in Invoice struct 332 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoicer_info 333 InvoicerInfo struct { 334 AdditionalNotes string `json:"additional_notes,omitempty"` 335 EmailAddress string `json:"email_address,omitempty"` 336 LogoUrl string `json:"logo_url,omitempty"` 337 Phones []InvoicerPhoneDetail `json:"phones,omitempty"` 338 TaxId string `json:"tax_id,omitempty"` 339 Website string `json:"website,omitempty"` 340 } 341 // Used in Invoice struct 342 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-item 343 InvoiceItem struct { 344 Name string `json:"name"` 345 Quantity string `json:"quantity"` 346 UnitAmount Money `json:"unit_amount"` 347 Description string `json:"description,omitempty"` 348 InvoiceDiscount InvoicingDiscount `json:"discount,omitempty"` 349 ID string `json:"id,omitempty"` 350 ItemDate string `json:"item_date,omitempty"` 351 Tax InvoiceTax `json:"tax,omitempty"` 352 UnitOfMeasure string `json:"unit_of_measure,omitempty"` 353 } 354 355 // used in InvoiceAddressPortable 356 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-address_details 357 InvoiceAddressDetails struct { 358 BuildingName string `json:"building_name,omitempty"` 359 DeliveryService string `json:"delivery_service,omitempty"` 360 StreetName string `json:"street_name,omitempty"` 361 StreetNumber string `json:"street_number,omitempty"` 362 StreetType string `json:"street_type,omitempty"` 363 SubBuilding string `json:"sub_building,omitempty"` 364 } 365 366 // used in InvoiceContactInfo 367 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-address_portable 368 InvoiceAddressPortable struct { 369 CountryCode string `json:"country_code"` 370 AddressDetails InvoiceAddressDetails `json:"address_details,omitempty"` 371 AddressLine1 string `json:"address_line_1,omitempty"` 372 AddressLine2 string `json:"address_line_2,omitempty"` 373 AddressLine3 string `json:"address_line_3,omitempty"` 374 AdminArea1 string `json:"admin_area_1,omitempty"` 375 AdminArea2 string `json:"admin_area_2,omitempty"` 376 AdminArea3 string `json:"admin_area_3,omitempty"` 377 AdminArea4 string `json:"admin_area_4,omitempty"` 378 PostalCode string `json:"postal_code,omitempty"` 379 } 380 381 // used in InvoicePaymentDetails 382 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-contact_information 383 InvoiceContactInfo struct { 384 BusinessName string `json:"business_name,omitempty"` 385 RecipientAddress InvoiceAddressPortable `json:"address,omitempty"` // address of the recipient. 386 RecipientName Name `json:"name,omitempty"` // The first and Last name of the recipient. 387 } 388 //used in InvoicePayments struct 389 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-payment_detail 390 InvoicePaymentDetails struct { 391 Method string `json:"method"` 392 Amount Money `json:"amount,omitempty"` 393 Note string `json:"note,omitempty"` 394 PaymentDate string `json:"payment_date,omitempty"` 395 PaymentID string `json:"payment_id,omitempty"` 396 ShippingInfo InvoiceContactInfo `json:"shipping_info,omitempty"` // The recipient's shipping information. 397 Type string `json:"type,omitempty"` 398 } 399 400 // used in Invoice 401 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-payments 402 InvoicePayments struct { 403 PaidAmount Money `json:"paid_amount,omitempty"` 404 Transactions []InvoicePaymentDetails `json:"transactions,omitempty"` 405 } 406 407 // used in InvoiceRecipientInfo 408 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-billing_info 409 InvoiceBillingInfo struct { 410 AdditionalInfo string `json:"additional_info,omitempty"` 411 EmailAddress string `json:"email_address,omitempty"` 412 Language string `json:"language,omitempty"` 413 Phones []InvoicerPhoneDetail `json:"phones,omitempty"` // invoice recipient's phone numbers. 414 } 415 // used in Invoice struct 416 // Doc: 417 InvoiceRecipientInfo struct { 418 BillingInfo InvoiceBillingInfo `json:"billing_info,omitempty"` // billing information for the invoice recipient. 419 ShippingInfo InvoiceContactInfo `json:"shipping_info,omitempty"` // recipient's shipping information. 420 } 421 422 // used in InvoiceRefund struct 423 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-refund_detail 424 InvoiceRefundDetails struct { 425 Method string `json:"method"` 426 RefundAmount Money `json:"amount,omitempty"` 427 RefundDate string `json:"refund_date,omitempty"` 428 RefundID string `json:"refund_id,omitempty"` 429 RefundType string `json:"type,omitempty"` 430 } 431 432 // used in Invoice struct 433 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-refunds 434 InvoiceRefund struct { 435 RefundAmount Money `json:"refund_amount,omitempty"` 436 RefundDetails []InvoiceRefundDetails `json:"transactions,omitempty"` 437 } 438 439 // used in Invoice struct 440 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#definition-email_address 441 InvoiceEmailAddress struct { 442 EmailAddress string `json:"email_address,omitempty"` 443 } 444 445 // to contain Invoice related fields 446 // Doc: https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get 447 Invoice struct { 448 AdditionalRecipients []InvoiceEmailAddress `json:"additional_recipients,omitempty"` // An array of one or more CC: emails to which notifications are sent. 449 AmountSummary AmountSummaryDetail `json:"amount,omitempty"` 450 Configuration InvoiceConfiguration `json:"configuration,omitempty"` 451 Detail InvoiceDetail `json:"detail,omitempty"` 452 DueAmount Money `json:"due_amount,omitempty"` // balance amount outstanding after payments. 453 Gratuity Money `json:"gratuity,omitempty"` // amount paid by the payer as gratuity to the invoicer. 454 ID string `json:"id,omitempty"` 455 Invoicer InvoicerInfo `json:"invoicer,omitempty"` 456 Items []InvoiceItem `json:"items,omitempty"` 457 Links []Link `json:"links,omitempty"` 458 ParentID string `json:"parent_id,omitempty"` 459 Payments InvoicePayments `json:"payments,omitempty"` 460 PrimaryRecipients []InvoiceRecipientInfo `json:"primary_recipients,omitempty"` 461 Refunds InvoiceRefund `json:"refunds,omitempty"` // List of refunds against this invoice. 462 Status string `json:"status,omitempty"` 463 } 464 465 // Doc: https://developer.paypal.com/api/orders/v2/#definition-payment_method 466 PaymentMethod struct { 467 PayeePreferred PayeePreferred `json:"payee_preferred,omitempty"` 468 StandardEntryClassCode StandardEntryClassCode `json:"standard_entry_class_code,omitempty"` 469 } 470 471 // Authorization struct 472 Authorization struct { 473 ID string `json:"id,omitempty"` 474 CustomID string `json:"custom_id,omitempty"` 475 InvoiceID string `json:"invoice_id,omitempty"` 476 Status string `json:"status,omitempty"` 477 StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` 478 Amount *PurchaseUnitAmount `json:"amount,omitempty"` 479 SellerProtection *SellerProtection `json:"seller_protection,omitempty"` 480 CreateTime *time.Time `json:"create_time,omitempty"` 481 UpdateTime *time.Time `json:"update_time,omitempty"` 482 ExpirationTime *time.Time `json:"expiration_time,omitempty"` 483 Links []Link `json:"links,omitempty"` 484 } 485 486 // AuthorizeOrderResponse . 487 AuthorizeOrderResponse struct { 488 CreateTime *time.Time `json:"create_time,omitempty"` 489 UpdateTime *time.Time `json:"update_time,omitempty"` 490 ID string `json:"id,omitempty"` 491 Status string `json:"status,omitempty"` 492 Intent string `json:"intent,omitempty"` 493 PurchaseUnits []PurchaseUnitRequest `json:"purchase_units,omitempty"` 494 Payer *PayerWithNameAndPhone `json:"payer,omitempty"` 495 } 496 497 // AuthorizeOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_authorize 498 AuthorizeOrderRequest struct { 499 PaymentSource *PaymentSource `json:"payment_source,omitempty"` 500 ApplicationContext ApplicationContext `json:"application_context,omitempty"` 501 } 502 503 // https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee 504 PlatformFee struct { 505 Amount *Money `json:"amount,omitempty"` 506 Payee *PayeeForOrders `json:"payee,omitempty"` 507 } 508 509 // https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction 510 PaymentInstruction struct { 511 PlatformFees []PlatformFee `json:"platform_fees,omitempty"` 512 DisbursementMode string `json:"disbursement_mode,omitempty"` 513 } 514 515 // https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture 516 PaymentCaptureRequest struct { 517 InvoiceID string `json:"invoice_id,omitempty"` 518 NoteToPayer string `json:"note_to_payer,omitempty"` 519 SoftDescriptor string `json:"soft_descriptor,omitempty"` 520 Amount *Money `json:"amount,omitempty"` 521 FinalCapture bool `json:"final_capture,omitempty"` 522 } 523 524 SellerProtection struct { 525 Status string `json:"status,omitempty"` 526 DisputeCategories []string `json:"dispute_categories,omitempty"` 527 } 528 529 // https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status_details 530 CaptureStatusDetails struct { 531 Reason string `json:"reason,omitempty"` 532 } 533 534 PaymentCaptureResponse struct { 535 Status string `json:"status,omitempty"` 536 StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` 537 ID string `json:"id,omitempty"` 538 Amount *Money `json:"amount,omitempty"` 539 InvoiceID string `json:"invoice_id,omitempty"` 540 FinalCapture bool `json:"final_capture,omitempty"` 541 DisbursementMode string `json:"disbursement_mode,omitempty"` 542 Links []Link `json:"links,omitempty"` 543 } 544 545 //https://developer.paypal.com/docs/api/payments/v2/#captures_get 546 CaptureDetailsResponse struct { 547 Status string `json:"status,omitempty"` 548 StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` 549 ID string `json:"id,omitempty"` 550 Amount *Money `json:"amount,omitempty"` 551 InvoiceID string `json:"invoice_id,omitempty"` 552 CustomID string `json:"custom_id,omitempty"` 553 SellerProtection *SellerProtection `json:"seller_protection,omitempty"` 554 FinalCapture bool `json:"final_capture,omitempty"` 555 SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"` 556 DisbursementMode string `json:"disbursement_mode,omitempty"` 557 Links []Link `json:"links,omitempty"` 558 UpdateTime *time.Time `json:"update_time,omitempty"` 559 CreateTime *time.Time `json:"create_time,omitempty"` 560 } 561 562 // CaptureOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_capture 563 CaptureOrderRequest struct { 564 PaymentSource *PaymentSource `json:"payment_source"` 565 } 566 567 // CaptureOrderMockResponse - https://developer.paypal.com/docs/api-basics/sandbox/request-headers/#test-api-error-handling-routines 568 CaptureOrderMockResponse struct { 569 MockApplicationCodes string `json:"mock_application_codes"` 570 } 571 572 // RefundOrderRequest - https://developer.paypal.com/docs/api/payments/v2/#captures_refund 573 RefundCaptureRequest struct { 574 Amount *Money `json:"amount,omitempty"` 575 InvoiceID string `json:"invoice_id,omitempty"` 576 NoteToPayer string `json:"note_to_payer,omitempty"` 577 } 578 579 // BatchHeader struct 580 BatchHeader struct { 581 Amount *AmountPayout `json:"amount,omitempty"` 582 Fees *AmountPayout `json:"fees,omitempty"` 583 PayoutBatchID string `json:"payout_batch_id,omitempty"` 584 BatchStatus string `json:"batch_status,omitempty"` 585 TimeCreated *time.Time `json:"time_created,omitempty"` 586 TimeCompleted *time.Time `json:"time_completed,omitempty"` 587 SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"` 588 } 589 590 // BillingAgreement struct 591 BillingAgreement struct { 592 Name string `json:"name,omitempty"` 593 Description string `json:"description,omitempty"` 594 StartDate JSONTime `json:"start_date,omitempty"` 595 Plan BillingPlan `json:"plan,omitempty"` 596 Payer Payer `json:"payer,omitempty"` 597 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` 598 OverrideMerchantPreferences *MerchantPreferences `json:"override_merchant_preferences,omitempty"` 599 } 600 601 // BillingAgreementFromToken struct 602 BillingAgreementFromToken struct { 603 ID string `json:"id,omitempty"` 604 Description string `json:"description,omitempty"` 605 Payer *Payer `json:"payer,omitempty"` 606 Plan BillingPlan `json:"plan,omitempty"` 607 Links []Link `json:"links,omitempty"` 608 } 609 610 // BillingAgreementToken response struct 611 BillingAgreementToken struct { 612 Links []Link `json:"links,omitempty"` 613 TokenID string `json:"token_id,omitempty"` 614 } 615 616 // Plan struct 617 Plan struct { 618 ID string `json:"id"` 619 Name string `json:"name"` 620 Description string `json:"description"` 621 CreateTime string `json:"create_time,omitempty"` 622 UpdateTime string `json:"update_time,omitempty"` 623 PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` 624 } 625 626 // BillingInfo struct 627 BillingInfo struct { 628 OutstandingBalance AmountPayout `json:"outstanding_balance,omitempty"` 629 CycleExecutions []CycleExecutions `json:"cycle_executions,omitempty"` 630 LastPayment LastPayment `json:"last_payment,omitempty"` 631 NextBillingTime time.Time `json:"next_billing_time,omitempty"` 632 FailedPaymentsCount int `json:"failed_payments_count,omitempty"` 633 } 634 635 // BillingPlan struct 636 BillingPlan struct { 637 ID string `json:"id,omitempty"` 638 Name string `json:"name,omitempty"` 639 Description string `json:"description,omitempty"` 640 Type string `json:"type,omitempty"` 641 PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` 642 MerchantPreferences *MerchantPreferences `json:"merchant_preferences,omitempty"` 643 } 644 645 // Capture struct 646 Capture struct { 647 ID string `json:"id,omitempty"` 648 Amount *Amount `json:"amount,omitempty"` 649 State string `json:"state,omitempty"` 650 ParentPayment string `json:"parent_payment,omitempty"` 651 TransactionFee string `json:"transaction_fee,omitempty"` 652 IsFinalCapture bool `json:"is_final_capture"` 653 CreateTime *time.Time `json:"create_time,omitempty"` 654 UpdateTime *time.Time `json:"update_time,omitempty"` 655 Links []Link `json:"links,omitempty"` 656 } 657 658 // ChargeModel struct 659 ChargeModel struct { 660 Type string `json:"type,omitempty"` 661 Amount AmountPayout `json:"amount,omitempty"` 662 } 663 664 // Client represents a Paypal REST API Client 665 Client struct { 666 // sync.Mutex 667 mu sync.Mutex 668 Client *http.Client 669 ClientID string 670 Secret string 671 APIBase string 672 Log io.Writer // If user set log file name all requests will be logged there 673 Token *TokenResponse 674 tokenExpiresAt time.Time 675 returnRepresentation bool 676 } 677 678 // CreditCard struct 679 CreditCard struct { 680 ID string `json:"id,omitempty"` 681 PayerID string `json:"payer_id,omitempty"` 682 ExternalCustomerID string `json:"external_customer_id,omitempty"` 683 Number string `json:"number"` 684 Type string `json:"type"` 685 ExpireMonth string `json:"expire_month"` 686 ExpireYear string `json:"expire_year"` 687 CVV2 string `json:"cvv2,omitempty"` 688 FirstName string `json:"first_name,omitempty"` 689 LastName string `json:"last_name,omitempty"` 690 BillingAddress *Address `json:"billing_address,omitempty"` 691 State string `json:"state,omitempty"` 692 ValidUntil string `json:"valid_until,omitempty"` 693 } 694 695 // CreditCards GET /v1/vault/credit-cards 696 CreditCards struct { 697 Items []CreditCard `json:"items"` 698 SharedListResponse 699 } 700 701 // CreditCardToken struct 702 CreditCardToken struct { 703 CreditCardID string `json:"credit_card_id"` 704 PayerID string `json:"payer_id,omitempty"` 705 Last4 string `json:"last4,omitempty"` 706 ExpireYear string `json:"expire_year,omitempty"` 707 ExpireMonth string `json:"expire_month,omitempty"` 708 } 709 710 // CreditCardsFilter struct 711 CreditCardsFilter struct { 712 PageSize int 713 Page int 714 } 715 716 // CreditCardField PATCH /v1/vault/credit-cards/credit_card_id 717 CreditCardField struct { 718 Operation string `json:"op"` 719 Path string `json:"path"` 720 Value string `json:"value"` 721 } 722 723 // Currency struct 724 Currency struct { 725 Currency string `json:"currency,omitempty"` 726 Value string `json:"value,omitempty"` 727 } 728 729 // CycleExecutions struct 730 CycleExecutions struct { 731 TenureType string `json:"tenure_type,omitempty"` 732 Sequence int `json:"sequence,omitempty"` 733 CyclesCompleted int `json:"cycles_completed,omitempty"` 734 CyclesRemaining int `json:"cycles_remaining,omitempty"` 735 TotalCycles int `json:"total_cycles,omitempty"` 736 } 737 738 // LastPayment struct 739 LastPayment struct { 740 Amount Money `json:"amount,omitempty"` 741 Time time.Time `json:"time,omitempty"` 742 } 743 744 // Details structure used in Amount structures as optional value 745 Details struct { 746 Subtotal string `json:"subtotal,omitempty"` 747 Shipping string `json:"shipping,omitempty"` 748 Tax string `json:"tax,omitempty"` 749 HandlingFee string `json:"handling_fee,omitempty"` 750 ShippingDiscount string `json:"shipping_discount,omitempty"` 751 Insurance string `json:"insurance,omitempty"` 752 GiftWrap string `json:"gift_wrap,omitempty"` 753 } 754 755 // ErrorResponseDetail struct 756 ErrorResponseDetail struct { 757 Field string `json:"field"` 758 Issue string `json:"issue"` 759 Name string `json:"name"` 760 Message string `json:"message"` 761 Description string `json:"description"` 762 Links []Link `json:"link"` 763 } 764 765 // ErrorResponse https://developer.paypal.com/docs/api/errors/ 766 ErrorResponse struct { 767 Response *http.Response `json:"-"` 768 Name string `json:"name"` 769 DebugID string `json:"debug_id"` 770 Message string `json:"message"` 771 InformationLink string `json:"information_link"` 772 Details []ErrorResponseDetail `json:"details"` 773 } 774 775 // ExecuteAgreementResponse struct 776 ExecuteAgreementResponse struct { 777 ID string `json:"id"` 778 State string `json:"state"` 779 Description string `json:"description,omitempty"` 780 Payer Payer `json:"payer"` 781 Plan BillingPlan `json:"plan"` 782 StartDate time.Time `json:"start_date"` 783 ShippingAddress ShippingAddress `json:"shipping_address"` 784 AgreementDetails AgreementDetails `json:"agreement_details"` 785 Links []Link `json:"links"` 786 } 787 788 // ExecuteResponse struct 789 ExecuteResponse struct { 790 ID string `json:"id"` 791 Links []Link `json:"links"` 792 State string `json:"state"` 793 Payer PaymentPayer `json:"payer"` 794 Transactions []Transaction `json:"transactions,omitempty"` 795 } 796 797 // FundingInstrument struct 798 FundingInstrument struct { 799 CreditCard *CreditCard `json:"credit_card,omitempty"` 800 CreditCardToken *CreditCardToken `json:"credit_card_token,omitempty"` 801 } 802 803 // Item struct 804 Item struct { 805 Name string `json:"name"` 806 UnitAmount *Money `json:"unit_amount,omitempty"` 807 Tax *Money `json:"tax,omitempty"` 808 Quantity string `json:"quantity"` 809 Description string `json:"description,omitempty"` 810 SKU string `json:"sku,omitempty"` 811 Category string `json:"category,omitempty"` 812 } 813 814 // ItemList struct 815 ItemList struct { 816 Items []Item `json:"items,omitempty"` 817 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` 818 } 819 820 // Link struct 821 Link struct { 822 Href string `json:"href"` 823 Rel string `json:"rel,omitempty"` 824 Method string `json:"method,omitempty"` 825 Description string `json:"description,omitempty"` 826 Enctype string `json:"enctype,omitempty"` 827 } 828 829 // PurchaseUnitAmount struct 830 PurchaseUnitAmount struct { 831 Currency string `json:"currency_code"` 832 Value string `json:"value"` 833 Breakdown *PurchaseUnitAmountBreakdown `json:"breakdown,omitempty"` 834 } 835 836 // PurchaseUnitAmountBreakdown struct 837 PurchaseUnitAmountBreakdown struct { 838 ItemTotal *Money `json:"item_total,omitempty"` 839 Shipping *Money `json:"shipping,omitempty"` 840 Handling *Money `json:"handling,omitempty"` 841 TaxTotal *Money `json:"tax_total,omitempty"` 842 Insurance *Money `json:"insurance,omitempty"` 843 ShippingDiscount *Money `json:"shipping_discount,omitempty"` 844 Discount *Money `json:"discount,omitempty"` 845 } 846 847 // Money struct 848 // 849 // https://developer.paypal.com/docs/api/orders/v2/#definition-money 850 Money struct { 851 Currency string `json:"currency_code"` 852 Value string `json:"value"` 853 } 854 855 // PurchaseUnit struct 856 PurchaseUnit struct { 857 ReferenceID string `json:"reference_id"` 858 Amount *PurchaseUnitAmount `json:"amount,omitempty"` 859 Payee *PayeeForOrders `json:"payee,omitempty"` 860 Payments *CapturedPayments `json:"payments,omitempty"` 861 PaymentInstruction *PaymentInstruction `json:"payment_instruction,omitempty"` 862 Description string `json:"description,omitempty"` 863 CustomID string `json:"custom_id,omitempty"` 864 InvoiceID string `json:"invoice_id,omitempty"` 865 ID string `json:"id,omitempty"` 866 SoftDescriptor string `json:"soft_descriptor,omitempty"` 867 Shipping *ShippingDetail `json:"shipping,omitempty"` 868 Items []Item `json:"items,omitempty"` 869 } 870 871 // TaxInfo used for orders. 872 TaxInfo struct { 873 TaxID string `json:"tax_id,omitempty"` 874 TaxIDType string `json:"tax_id_type,omitempty"` 875 } 876 877 // PhoneWithTypeNumber struct for PhoneWithType 878 PhoneWithTypeNumber struct { 879 NationalNumber string `json:"national_number,omitempty"` 880 } 881 882 // PhoneWithType struct used for orders 883 PhoneWithType struct { 884 PhoneType string `json:"phone_type,omitempty"` 885 PhoneNumber *PhoneWithTypeNumber `json:"phone_number,omitempty"` 886 } 887 888 // CreateOrderPayerName create order payer name 889 CreateOrderPayerName struct { 890 GivenName string `json:"given_name,omitempty"` 891 Surname string `json:"surname,omitempty"` 892 } 893 894 // CreateOrderPayer used with create order requests 895 CreateOrderPayer struct { 896 Name *CreateOrderPayerName `json:"name,omitempty"` 897 EmailAddress string `json:"email_address,omitempty"` 898 PayerID string `json:"payer_id,omitempty"` 899 Phone *PhoneWithType `json:"phone,omitempty"` 900 BirthDate string `json:"birth_date,omitempty"` 901 TaxInfo *TaxInfo `json:"tax_info,omitempty"` 902 Address *ShippingDetailAddressPortable `json:"address,omitempty"` 903 } 904 905 // PurchaseUnitRequest struct 906 PurchaseUnitRequest struct { 907 ReferenceID string `json:"reference_id,omitempty"` 908 Amount *PurchaseUnitAmount `json:"amount"` 909 Payee *PayeeForOrders `json:"payee,omitempty"` 910 Description string `json:"description,omitempty"` 911 CustomID string `json:"custom_id,omitempty"` 912 InvoiceID string `json:"invoice_id,omitempty"` 913 SoftDescriptor string `json:"soft_descriptor,omitempty"` 914 Items []Item `json:"items,omitempty"` 915 Shipping *ShippingDetail `json:"shipping,omitempty"` 916 PaymentInstruction *PaymentInstruction `json:"payment_instruction,omitempty"` 917 } 918 919 // MerchantPreferences struct 920 MerchantPreferences struct { 921 SetupFee *AmountPayout `json:"setup_fee,omitempty"` 922 ReturnURL string `json:"return_url,omitempty"` 923 CancelURL string `json:"cancel_url,omitempty"` 924 AutoBillAmount string `json:"auto_bill_amount,omitempty"` 925 InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"` 926 MaxFailAttempts string `json:"max_fail_attempts,omitempty"` 927 } 928 929 // Order struct 930 Order struct { 931 ID string `json:"id,omitempty"` 932 Status string `json:"status,omitempty"` 933 Intent string `json:"intent,omitempty"` 934 Payer *PayerWithNameAndPhone `json:"payer,omitempty"` 935 PurchaseUnits []PurchaseUnit `json:"purchase_units,omitempty"` 936 Links []Link `json:"links,omitempty"` 937 CreateTime *time.Time `json:"create_time,omitempty"` 938 UpdateTime *time.Time `json:"update_time,omitempty"` 939 } 940 941 // ExchangeRate struct 942 // 943 // https://developer.paypal.com/docs/api/orders/v2/#definition-exchange_rate 944 ExchangeRate struct { 945 SourceCurrency string `json:"source_currency"` 946 TargetCurrency string `json:"target_currency"` 947 Value string `json:"value"` 948 } 949 950 // SellerReceivableBreakdown has the detailed breakdown of the capture activity. 951 SellerReceivableBreakdown struct { 952 GrossAmount *Money `json:"gross_amount,omitempty"` 953 PaypalFee *Money `json:"paypal_fee,omitempty"` 954 PaypalFeeInReceivableCurrency *Money `json:"paypal_fee_in_receivable_currency,omitempty"` 955 NetAmount *Money `json:"net_amount,omitempty"` 956 ReceivableAmount *Money `json:"receivable_amount,omitempty"` 957 ExchangeRate *ExchangeRate `json:"exchange_rate,omitempty"` 958 PlatformFees []PlatformFee `json:"platform_fees,omitempty"` 959 } 960 961 // CaptureAmount struct 962 CaptureAmount struct { 963 Status string `json:"status,omitempty"` 964 ID string `json:"id,omitempty"` 965 CustomID string `json:"custom_id,omitempty"` 966 Amount *PurchaseUnitAmount `json:"amount,omitempty"` 967 SellerProtection *SellerProtection `json:"seller_protection,omitempty"` 968 SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"` 969 } 970 971 // CapturedPayments has the amounts for a captured order 972 CapturedPayments struct { 973 Captures []CaptureAmount `json:"captures,omitempty"` 974 } 975 976 // CapturedPurchaseItem are items for a captured order 977 CapturedPurchaseItem struct { 978 Quantity string `json:"quantity"` 979 Name string `json:"name"` 980 SKU string `json:"sku,omitempty"` 981 Description string `json:"description,omitempty"` 982 } 983 984 // CapturedPurchaseUnit are purchase units for a captured order 985 CapturedPurchaseUnit struct { 986 Items []CapturedPurchaseItem `json:"items,omitempty"` 987 ReferenceID string `json:"reference_id"` 988 Shipping CapturedPurchaseUnitShipping `json:"shipping,omitempty"` 989 Payments *CapturedPayments `json:"payments,omitempty"` 990 } 991 992 CapturedPurchaseUnitShipping struct { 993 Address ShippingDetailAddressPortable `json:"address,omitempty"` 994 } 995 996 // PayerWithNameAndPhone struct 997 PayerWithNameAndPhone struct { 998 Name *CreateOrderPayerName `json:"name,omitempty"` 999 EmailAddress string `json:"email_address,omitempty"` 1000 Phone *PhoneWithType `json:"phone,omitempty"` 1001 PayerID string `json:"payer_id,omitempty"` 1002 BirthDate string `json:"birth_date,omitempty"` 1003 TaxInfo *TaxInfo `json:"tax_info,omitempty"` 1004 Address *ShippingDetailAddressPortable `json:"address,omitempty"` 1005 } 1006 1007 // CaptureOrderResponse is the response for capture order 1008 CaptureOrderResponse struct { 1009 ID string `json:"id,omitempty"` 1010 Status string `json:"status,omitempty"` 1011 Payer *PayerWithNameAndPhone `json:"payer,omitempty"` 1012 Address *Address `json:"address,omitempty"` 1013 PurchaseUnits []CapturedPurchaseUnit `json:"purchase_units,omitempty"` 1014 } 1015 1016 // Payer struct 1017 Payer struct { 1018 PaymentMethod string `json:"payment_method"` 1019 FundingInstruments []FundingInstrument `json:"funding_instruments,omitempty"` 1020 PayerInfo *PayerInfo `json:"payer_info,omitempty"` 1021 Status string `json:"payer_status,omitempty"` 1022 } 1023 1024 // PayerInfo struct 1025 PayerInfo struct { 1026 Email string `json:"email,omitempty"` 1027 FirstName string `json:"first_name,omitempty"` 1028 LastName string `json:"last_name,omitempty"` 1029 PayerID string `json:"payer_id,omitempty"` 1030 Phone string `json:"phone,omitempty"` 1031 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` 1032 TaxIDType string `json:"tax_id_type,omitempty"` 1033 TaxID string `json:"tax_id,omitempty"` 1034 CountryCode string `json:"country_code"` 1035 } 1036 1037 // PaymentDefinition struct 1038 PaymentDefinition struct { 1039 ID string `json:"id,omitempty"` 1040 Name string `json:"name,omitempty"` 1041 Type string `json:"type,omitempty"` 1042 Frequency string `json:"frequency,omitempty"` 1043 FrequencyInterval string `json:"frequency_interval,omitempty"` 1044 Amount AmountPayout `json:"amount,omitempty"` 1045 Cycles string `json:"cycles,omitempty"` 1046 ChargeModels []ChargeModel `json:"charge_models,omitempty"` 1047 } 1048 1049 // PaymentOptions struct 1050 PaymentOptions struct { 1051 AllowedPaymentMethod string `json:"allowed_payment_method,omitempty"` 1052 } 1053 1054 // PaymentPatch PATCH /v2/payments/payment/{payment_id) 1055 PaymentPatch struct { 1056 Operation string `json:"op"` 1057 Path string `json:"path"` 1058 Value interface{} `json:"value"` 1059 } 1060 1061 // PaymentPayer struct 1062 PaymentPayer struct { 1063 PaymentMethod string `json:"payment_method"` 1064 Status string `json:"status,omitempty"` 1065 PayerInfo *PayerInfo `json:"payer_info,omitempty"` 1066 } 1067 1068 // PaymentResponse structure 1069 PaymentResponse struct { 1070 ID string `json:"id"` 1071 State string `json:"state"` 1072 Intent string `json:"intent"` 1073 Payer Payer `json:"payer"` 1074 Transactions []Transaction `json:"transactions"` 1075 Links []Link `json:"links"` 1076 } 1077 1078 // PaymentSource structure 1079 PaymentSource struct { 1080 Card *PaymentSourceCard `json:"card,omitempty"` 1081 Token *PaymentSourceToken `json:"token,omitempty"` 1082 } 1083 1084 // PaymentSourceCard structure 1085 PaymentSourceCard struct { 1086 ID string `json:"id"` 1087 Name string `json:"name"` 1088 Number string `json:"number"` 1089 Expiry string `json:"expiry"` 1090 SecurityCode string `json:"security_code"` 1091 LastDigits string `json:"last_digits"` 1092 CardType string `json:"card_type"` 1093 BillingAddress *CardBillingAddress `json:"billing_address"` 1094 } 1095 1096 // CardBillingAddress structure 1097 CardBillingAddress struct { 1098 AddressLine1 string `json:"address_line_1"` 1099 AddressLine2 string `json:"address_line_2"` 1100 AdminArea2 string `json:"admin_area_2"` 1101 AdminArea1 string `json:"admin_area_1"` 1102 PostalCode string `json:"postal_code"` 1103 CountryCode string `json:"country_code"` 1104 } 1105 1106 // PaymentSourceToken structure 1107 PaymentSourceToken struct { 1108 ID string `json:"id"` 1109 Type string `json:"type"` 1110 } 1111 1112 // Payout struct 1113 Payout struct { 1114 SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header"` 1115 Items []PayoutItem `json:"items"` 1116 } 1117 1118 // PayoutItem struct 1119 PayoutItem struct { 1120 RecipientType string `json:"recipient_type"` 1121 RecipientWallet string `json:"recipient_wallet"` 1122 Receiver string `json:"receiver"` 1123 Amount *AmountPayout `json:"amount"` 1124 Note string `json:"note,omitempty"` 1125 SenderItemID string `json:"sender_item_id,omitempty"` 1126 } 1127 1128 // PayoutItemResponse struct 1129 PayoutItemResponse struct { 1130 PayoutItemID string `json:"payout_item_id"` 1131 TransactionID string `json:"transaction_id"` 1132 TransactionStatus string `json:"transaction_status"` 1133 PayoutBatchID string `json:"payout_batch_id,omitempty"` 1134 PayoutItemFee *AmountPayout `json:"payout_item_fee,omitempty"` 1135 PayoutItem *PayoutItem `json:"payout_item"` 1136 TimeProcessed *time.Time `json:"time_processed,omitempty"` 1137 Links []Link `json:"links"` 1138 Error ErrorResponse `json:"errors,omitempty"` 1139 } 1140 1141 // PayoutResponse struct 1142 PayoutResponse struct { 1143 BatchHeader *BatchHeader `json:"batch_header"` 1144 Items []PayoutItemResponse `json:"items"` 1145 Links []Link `json:"links"` 1146 } 1147 1148 // RedirectURLs struct 1149 RedirectURLs struct { 1150 ReturnURL string `json:"return_url,omitempty"` 1151 CancelURL string `json:"cancel_url,omitempty"` 1152 } 1153 1154 // Refund struct 1155 Refund struct { 1156 ID string `json:"id,omitempty"` 1157 Amount *Amount `json:"amount,omitempty"` 1158 CreateTime *time.Time `json:"create_time,omitempty"` 1159 State string `json:"state,omitempty"` 1160 CaptureID string `json:"capture_id,omitempty"` 1161 ParentPayment string `json:"parent_payment,omitempty"` 1162 UpdateTime *time.Time `json:"update_time,omitempty"` 1163 SaleID string `json:"sale_id,omitempty"` 1164 } 1165 1166 // RefundResponse . 1167 RefundResponse struct { 1168 ID string `json:"id,omitempty"` 1169 Amount *PurchaseUnitAmount `json:"amount,omitempty"` 1170 Status string `json:"status,omitempty"` 1171 Links []Link `json:"links,omitempty"` 1172 } 1173 1174 // Related struct 1175 Related struct { 1176 Sale *Sale `json:"sale,omitempty"` 1177 Authorization *Authorization `json:"authorization,omitempty"` 1178 Order *Order `json:"order,omitempty"` 1179 Capture *Capture `json:"capture,omitempty"` 1180 Refund *Refund `json:"refund,omitempty"` 1181 } 1182 1183 // Sale struct 1184 Sale struct { 1185 ID string `json:"id,omitempty"` 1186 Amount *Amount `json:"amount,omitempty"` 1187 TransactionFee *Currency `json:"transaction_fee,omitempty"` 1188 Description string `json:"description,omitempty"` 1189 CreateTime *time.Time `json:"create_time,omitempty"` 1190 State string `json:"state,omitempty"` 1191 ParentPayment string `json:"parent_payment,omitempty"` 1192 UpdateTime *time.Time `json:"update_time,omitempty"` 1193 PaymentMode string `json:"payment_mode,omitempty"` 1194 PendingReason string `json:"pending_reason,omitempty"` 1195 ReasonCode string `json:"reason_code,omitempty"` 1196 ClearingTime string `json:"clearing_time,omitempty"` 1197 ProtectionEligibility string `json:"protection_eligibility,omitempty"` 1198 ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"` 1199 Links []Link `json:"links,omitempty"` 1200 } 1201 1202 // SenderBatchHeader struct 1203 SenderBatchHeader struct { 1204 EmailSubject string `json:"email_subject"` 1205 EmailMessage string `json:"email_message"` 1206 SenderBatchID string `json:"sender_batch_id,omitempty"` 1207 } 1208 1209 //ShippingAmount struct 1210 ShippingAmount struct { 1211 Money 1212 } 1213 1214 // ShippingAddress struct 1215 ShippingAddress struct { 1216 RecipientName string `json:"recipient_name,omitempty"` 1217 Type string `json:"type,omitempty"` 1218 Line1 string `json:"line1"` 1219 Line2 string `json:"line2,omitempty"` 1220 City string `json:"city"` 1221 CountryCode string `json:"country_code"` 1222 PostalCode string `json:"postal_code,omitempty"` 1223 State string `json:"state,omitempty"` 1224 Phone string `json:"phone,omitempty"` 1225 } 1226 1227 // ShippingDetailAddressPortable used with create orders 1228 ShippingDetailAddressPortable struct { 1229 AddressLine1 string `json:"address_line_1,omitempty"` 1230 AddressLine2 string `json:"address_line_2,omitempty"` 1231 AdminArea1 string `json:"admin_area_1,omitempty"` 1232 AdminArea2 string `json:"admin_area_2,omitempty"` 1233 PostalCode string `json:"postal_code,omitempty"` 1234 CountryCode string `json:"country_code,omitempty"` 1235 } 1236 1237 // Name struct 1238 //Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#definition-name 1239 Name struct { 1240 FullName string `json:"full_name,omitempty"` 1241 Suffix string `json:"suffix,omitempty"` 1242 Prefix string `json:"prefix,omitempty"` 1243 GivenName string `json:"given_name,omitempty"` 1244 Surname string `json:"surname,omitempty"` 1245 MiddleName string `json:"middle_name,omitempty"` 1246 } 1247 1248 // ShippingDetail struct 1249 ShippingDetail struct { 1250 Name *Name `json:"name,omitempty"` 1251 Address *ShippingDetailAddressPortable `json:"address,omitempty"` 1252 } 1253 1254 // Subscriber struct 1255 Subscriber struct { 1256 PayerID string `json:"payer_id"` 1257 ShippingAddress ShippingDetail `json:"shipping_address,omitempty"` 1258 Name CreateOrderPayerName `json:"name,omitempty"` 1259 EmailAddress string `json:"email_address,omitempty"` 1260 } 1261 1262 expirationTime int64 1263 1264 // TokenResponse is for API response for the /oauth2/token endpoint 1265 TokenResponse struct { 1266 RefreshToken string `json:"refresh_token"` 1267 Token string `json:"access_token"` 1268 Type string `json:"token_type"` 1269 ExpiresIn expirationTime `json:"expires_in"` 1270 } 1271 1272 // Transaction struct 1273 Transaction struct { 1274 Amount *Amount `json:"amount"` 1275 Description string `json:"description,omitempty"` 1276 ItemList *ItemList `json:"item_list,omitempty"` 1277 InvoiceNumber string `json:"invoice_number,omitempty"` 1278 Custom string `json:"custom,omitempty"` 1279 SoftDescriptor string `json:"soft_descriptor,omitempty"` 1280 RelatedResources []Related `json:"related_resources,omitempty"` 1281 PaymentOptions *PaymentOptions `json:"payment_options,omitempty"` 1282 NotifyURL string `json:"notify_url,omitempty"` 1283 OrderURL string `json:"order_url,omitempty"` 1284 Payee *Payee `json:"payee,omitempty"` 1285 } 1286 1287 //Payee struct 1288 Payee struct { 1289 Email string `json:"email"` 1290 } 1291 1292 // PayeeForOrders struct 1293 PayeeForOrders struct { 1294 EmailAddress string `json:"email_address,omitempty"` 1295 MerchantID string `json:"merchant_id,omitempty"` 1296 } 1297 1298 // UserInfo struct 1299 UserInfo struct { 1300 ID string `json:"user_id"` 1301 Name string `json:"name"` 1302 GivenName string `json:"given_name"` 1303 FamilyName string `json:"family_name"` 1304 Email string `json:"email"` 1305 Verified bool `json:"verified,omitempty,string"` 1306 Gender string `json:"gender,omitempty"` 1307 BirthDate string `json:"birthdate,omitempty"` 1308 ZoneInfo string `json:"zoneinfo,omitempty"` 1309 Locale string `json:"locale,omitempty"` 1310 Phone string `json:"phone_number,omitempty"` 1311 Address *Address `json:"address,omitempty"` 1312 VerifiedAccount bool `json:"verified_account,omitempty,string"` 1313 AccountType string `json:"account_type,omitempty"` 1314 AgeRange string `json:"age_range,omitempty"` 1315 PayerID string `json:"payer_id,omitempty"` 1316 } 1317 1318 // WebProfile represents the configuration of the payment web payment experience 1319 // 1320 // https://developer.paypal.com/docs/api/payment-experience/ 1321 WebProfile struct { 1322 ID string `json:"id,omitempty"` 1323 Name string `json:"name"` 1324 Presentation Presentation `json:"presentation,omitempty"` 1325 InputFields InputFields `json:"input_fields,omitempty"` 1326 FlowConfig FlowConfig `json:"flow_config,omitempty"` 1327 } 1328 1329 // Presentation represents the branding and locale that a customer sees on 1330 // redirect payments 1331 // 1332 // https://developer.paypal.com/docs/api/payment-experience/#definition-presentation 1333 Presentation struct { 1334 BrandName string `json:"brand_name,omitempty"` 1335 LogoImage string `json:"logo_image,omitempty"` 1336 LocaleCode string `json:"locale_code,omitempty"` 1337 } 1338 1339 // InputFields represents the fields that are displayed to a customer on 1340 // redirect payments 1341 // 1342 // https://developer.paypal.com/docs/api/payment-experience/#definition-input_fields 1343 InputFields struct { 1344 AllowNote bool `json:"allow_note,omitempty"` 1345 NoShipping uint `json:"no_shipping,omitempty"` 1346 AddressOverride uint `json:"address_override,omitempty"` 1347 } 1348 1349 // FlowConfig represents the general behaviour of redirect payment pages 1350 // 1351 // https://developer.paypal.com/docs/api/payment-experience/#definition-flow_config 1352 FlowConfig struct { 1353 LandingPageType string `json:"landing_page_type,omitempty"` 1354 BankTXNPendingURL string `json:"bank_txn_pending_url,omitempty"` 1355 UserAction string `json:"user_action,omitempty"` 1356 } 1357 1358 // VerifyWebhookResponse struct 1359 VerifyWebhookResponse struct { 1360 VerificationStatus string `json:"verification_status,omitempty"` 1361 } 1362 1363 WebhookEventTypesResponse struct { 1364 EventTypes []WebhookEventType `json:"event_types"` 1365 } 1366 1367 // Webhook struct 1368 Webhook struct { 1369 ID string `json:"id"` 1370 URL string `json:"url"` 1371 EventTypes []WebhookEventType `json:"event_types"` 1372 Links []Link `json:"links"` 1373 } 1374 1375 // Event struct. 1376 // 1377 // The basic webhook event data type. This struct is intended to be 1378 // embedded into resource type specific event structs. 1379 Event struct { 1380 ID string `json:"id"` 1381 CreateTime time.Time `json:"create_time"` 1382 ResourceType string `json:"resource_type"` 1383 EventType string `json:"event_type"` 1384 Summary string `json:"summary,omitempty"` 1385 Links []Link `json:"links"` 1386 EventVersion string `json:"event_version,omitempty"` 1387 ResourceVersion string `json:"resource_version,omitempty"` 1388 } 1389 1390 AnyEvent struct { 1391 Event 1392 Resource json.RawMessage `json:"resource"` 1393 } 1394 1395 // WebhookEventType struct 1396 WebhookEventType struct { 1397 Name string `json:"name"` 1398 Description string `json:"description"` 1399 Status string `json:"status,omitempty"` 1400 } 1401 1402 // CreateWebhookRequest struct 1403 CreateWebhookRequest struct { 1404 URL string `json:"url"` 1405 EventTypes []WebhookEventType `json:"event_types"` 1406 } 1407 1408 ListWebhookResponse struct { 1409 Webhooks []Webhook `json:"webhooks"` 1410 } 1411 1412 WebhookField struct { 1413 Operation string `json:"op"` 1414 Path string `json:"path"` 1415 Value interface{} `json:"value"` 1416 } 1417 1418 // Resource is a mix of fields from several webhook resource types. 1419 // 1420 // Deprecated: Add implementation of specific resource types in your own 1421 // code and don't use this catch all struct, you show know which resource 1422 // type you are expecting and handle that type only. 1423 // 1424 // Every resource struct type should be unique for every combination of 1425 // "resource_type"/"resource_version" combination of the Event type / 1426 // webhook message. 1427 Resource struct { 1428 ID string `json:"id,omitempty"` 1429 Status string `json:"status,omitempty"` 1430 StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` 1431 Amount *PurchaseUnitAmount `json:"amount,omitempty"` 1432 UpdateTime string `json:"update_time,omitempty"` 1433 CreateTime string `json:"create_time,omitempty"` 1434 ExpirationTime string `json:"expiration_time,omitempty"` 1435 SellerProtection *SellerProtection `json:"seller_protection,omitempty"` 1436 FinalCapture bool `json:"final_capture,omitempty"` 1437 SellerPayableBreakdown *CaptureSellerBreakdown `json:"seller_payable_breakdown,omitempty"` 1438 SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"` 1439 NoteToPayer string `json:"note_to_payer,omitempty"` 1440 CustomID string `json:"custom_id,omitempty"` 1441 PartnerClientID string `json:"partner_client_id,omitempty"` 1442 MerchantID string `json:"merchant_id,omitempty"` 1443 Intent string `json:"intent,omitempty"` 1444 BillingAgreementID *string `json:"billing_agreement_id,omitempty"` 1445 PurchaseUnits []*PurchaseUnitRequest `json:"purchase_units,omitempty"` 1446 Payer *PayerWithNameAndPhone `json:"payer,omitempty"` 1447 Links []Link `json:"links,omitempty"` 1448 } 1449 1450 CaptureSellerBreakdown struct { 1451 GrossAmount PurchaseUnitAmount `json:"gross_amount"` 1452 PayPalFee PurchaseUnitAmount `json:"paypal_fee"` 1453 NetAmount PurchaseUnitAmount `json:"net_amount"` 1454 TotalRefundedAmount *PurchaseUnitAmount `json:"total_refunded_amount,omitempty"` 1455 } 1456 1457 ReferralRequest struct { 1458 TrackingID string `json:"tracking_id"` 1459 PartnerConfigOverride *PartnerConfigOverride `json:"partner_config_override,omitempty"` 1460 Operations []Operation `json:"operations,omitempty"` 1461 Products []string `json:"products,omitempty"` 1462 LegalConsents []Consent `json:"legal_consents,omitempty"` 1463 } 1464 1465 ReferralResponse struct { 1466 Links []Link `json:"links,omitempty"` 1467 } 1468 1469 PartnerConfigOverride struct { 1470 PartnerLogoURL string `json:"partner_logo_url,omitempty"` 1471 ReturnURL string `json:"return_url,omitempty"` 1472 ReturnURLDescription string `json:"return_url_description,omitempty"` 1473 ActionRenewalURL string `json:"action_renewal_url,omitempty"` 1474 ShowAddCreditCard *bool `json:"show_add_credit_card,omitempty"` 1475 } 1476 1477 Operation struct { 1478 Operation string `json:"operation"` 1479 APIIntegrationPreference *IntegrationDetails `json:"api_integration_preference,omitempty"` 1480 } 1481 1482 IntegrationDetails struct { 1483 RestAPIIntegration *RestAPIIntegration `json:"rest_api_integration,omitempty"` 1484 } 1485 1486 RestAPIIntegration struct { 1487 IntegrationMethod string `json:"integration_method"` 1488 IntegrationType string `json:"integration_type"` 1489 ThirdPartyDetails ThirdPartyDetails `json:"third_party_details"` 1490 } 1491 1492 ThirdPartyDetails struct { 1493 Features []string `json:"features"` 1494 } 1495 1496 Consent struct { 1497 Type string `json:"type"` 1498 Granted bool `json:"granted"` 1499 } 1500 1501 SearchItemDetails struct { 1502 ItemCode string `json:"item_code"` 1503 ItemName string `json:"item_name"` 1504 ItemDescription string `json:"item_description"` 1505 ItemOptions string `json:"item_options"` 1506 ItemQuantity string `json:"item_quantity"` 1507 ItemUnitPrice Money `json:"item_unit_price"` 1508 ItemAmount Money `json:"item_amount"` 1509 DiscountAmount *Money `json:"discount_amount"` 1510 AdjustmentAmount *Money `json:"adjustment_amount"` 1511 GiftWrapAmount *Money `json:"gift_wrap_amount"` 1512 TaxPercentage string `json:"tax_percentage"` 1513 TaxAmounts []SearchTaxAmount `json:"tax_amounts"` 1514 BasicShippingAmount *Money `json:"basic_shipping_amount"` 1515 ExtraShippingAmount *Money `json:"extra_shipping_amount"` 1516 HandlingAmount *Money `json:"handling_amount"` 1517 InsuranceAmount *Money `json:"insurance_amount"` 1518 TotalItemAmount Money `json:"total_item_amount"` 1519 InvoiceNumber string `json:"invoice_number"` 1520 CheckoutOptions []SearchCheckoutOption `json:"checkout_options"` 1521 } 1522 1523 SearchCheckoutOption struct { 1524 CheckoutOptionName string `json:"checkout_option_name"` 1525 CheckoutOptionValue string `json:"checkout_option_value"` 1526 } 1527 1528 SearchCartInfo struct { 1529 ItemDetails []SearchItemDetails `json:"item_details"` 1530 TaxInclusive *bool `json:"tax_inclusive"` 1531 PayPalInvoiceID string `json:"paypal_invoice_id"` 1532 } 1533 1534 SearchShippingInfo struct { 1535 Name string `json:"name"` 1536 Method string `json:"method"` 1537 Address Address `json:"address"` 1538 SecondaryShippingAddress *Address `json:"secondary_shipping_address"` 1539 } 1540 1541 SearchPayerName struct { 1542 GivenName string `json:"given_name"` 1543 Surname string `json:"surname"` 1544 } 1545 1546 SearchPayerInfo struct { 1547 AccountID string `json:"account_id"` 1548 EmailAddress string `json:"email_address"` 1549 PhoneNumber *PhoneWithTypeNumber `json:"phone_number"` 1550 AddressStatus string `json:"address_status"` 1551 PayerStatus string `json:"payer_status"` 1552 PayerName SearchPayerName `json:"payer_name"` 1553 CountryCode string `json:"country_code"` 1554 Address *Address `json:"address"` 1555 } 1556 1557 SearchTaxAmount struct { 1558 TaxAmount Money `json:"tax_amount"` 1559 } 1560 1561 SearchTransactionInfo struct { 1562 PayPalAccountID string `json:"paypal_account_id"` 1563 TransactionID string `json:"transaction_id"` 1564 PayPalReferenceID string `json:"paypal_reference_id"` 1565 PayPalReferenceIDType string `json:"paypal_reference_id_type"` 1566 TransactionEventCode string `json:"transaction_event_code"` 1567 TransactionInitiationDate JSONTime `json:"transaction_initiation_date"` 1568 TransactionUpdatedDate JSONTime `json:"transaction_updated_date"` 1569 TransactionAmount Money `json:"transaction_amount"` 1570 FeeAmount *Money `json:"fee_amount"` 1571 InsuranceAmount *Money `json:"insurance_amount"` 1572 ShippingAmount *Money `json:"shipping_amount"` 1573 ShippingDiscountAmount *Money `json:"shipping_discount_amount"` 1574 ShippingTaxAmount *Money `json:"shipping_tax_amount"` 1575 OtherAmount *Money `json:"other_amount"` 1576 TipAmount *Money `json:"tip_amount"` 1577 TransactionStatus string `json:"transaction_status"` 1578 TransactionSubject string `json:"transaction_subject"` 1579 PaymentTrackingID string `json:"payment_tracking_id"` 1580 BankReferenceID string `json:"bank_reference_id"` 1581 TransactionNote string `json:"transaction_note"` 1582 EndingBalance *Money `json:"ending_balance"` 1583 AvailableBalance *Money `json:"available_balance"` 1584 InvoiceID string `json:"invoice_id"` 1585 CustomField string `json:"custom_field"` 1586 ProtectionEligibility string `json:"protection_eligibility"` 1587 CreditTerm string `json:"credit_term"` 1588 CreditTransactionalFee *Money `json:"credit_transactional_fee"` 1589 CreditPromotionalFee *Money `json:"credit_promotional_fee"` 1590 AnnualPercentageRate string `json:"annual_percentage_rate"` 1591 PaymentMethodType string `json:"payment_method_type"` 1592 } 1593 1594 SearchTransactionDetails struct { 1595 TransactionInfo SearchTransactionInfo `json:"transaction_info"` 1596 PayerInfo *SearchPayerInfo `json:"payer_info"` 1597 ShippingInfo *SearchShippingInfo `json:"shipping_info"` 1598 CartInfo *SearchCartInfo `json:"cart_info"` 1599 } 1600 1601 SharedResponse struct { 1602 CreateTime string `json:"create_time"` 1603 UpdateTime string `json:"update_time"` 1604 Links []Link `json:"links"` 1605 } 1606 1607 ListParams struct { 1608 Page string `json:"page,omitempty"` //Default: 0. 1609 PageSize string `json:"page_size,omitempty"` //Default: 10. 1610 TotalRequired string `json:"total_required,omitempty"` //Default: no. 1611 } 1612 1613 SharedListResponse struct { 1614 TotalItems int `json:"total_items,omitempty"` 1615 TotalPages int `json:"total_pages,omitempty"` 1616 Links []Link `json:"links,omitempty"` 1617 } 1618 ) 1619 1620 // Error method implementation for ErrorResponse struct 1621 func (r *ErrorResponse) Error() string { 1622 return fmt.Sprintf("%v %v: %d %s, %+v", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message, r.Details) 1623 } 1624 1625 // MarshalJSON for JSONTime 1626 func (t JSONTime) MarshalJSON() ([]byte, error) { 1627 stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339)) 1628 return []byte(stamp), nil 1629 } 1630 1631 // UnmarshalJSON for JSONTime, timezone offset is missing a colon ':" 1632 func (t *JSONTime) UnmarshalJSON(b []byte) error { 1633 s := strings.Trim(string(b), `"`) 1634 nt, err := time.Parse("2006-01-02T15:04:05Z0700", s) 1635 *t = JSONTime(nt) 1636 return err 1637 } 1638 1639 func (e *expirationTime) UnmarshalJSON(b []byte) error { 1640 var n json.Number 1641 err := json.Unmarshal(b, &n) 1642 if err != nil { 1643 return err 1644 } 1645 i, err := n.Int64() 1646 if err != nil { 1647 return err 1648 } 1649 *e = expirationTime(i) 1650 return nil 1651 }