From 205f33b0ddf636a23e07a7a52da7d40fabb06479 Mon Sep 17 00:00:00 2001 From: tianyingchun Date: Wed, 15 May 2024 18:14:12 +0800 Subject: [PATCH] refactor: refactor add request body input typings --- .changeset/ten-beds-shout.md | 6 + .eslintrc.cjs | 2 +- CONTRIBUTING.md | 9 +- cache.config.mjs | 2 +- codegen.cjs | 44 - docs/typings/orders/lib.d.ts | 669 ++++++++++++++ docs/typings/payments/lib.d.ts | 858 ++++++++++++++++++ package.json | 1 + .../AuthorizeIntentExamples/authorizeOrder.ts | 4 +- .../AuthorizeIntentExamples/captureOrder.ts | 6 +- .../AuthorizeIntentExamples/createOrder.ts | 10 +- samples/CaptureIntentExamples/captureOrder.ts | 6 +- samples/CaptureIntentExamples/createOrder.ts | 6 +- samples/Common/errorSample.ts | 10 +- samples/Common/getOrder.ts | 4 +- samples/Common/patchOrder.ts | 6 +- samples/Common/payPalClient.ts | 12 +- samples/Common/refundOrder.ts | 6 +- src/core/AccessToken.ts | 37 +- src/core/AccessTokenRequest.ts | 14 +- src/core/HttpRequestBase.ts | 36 +- src/core/PayPalEnvironment.ts | 3 + src/core/PayPalHttpClient.ts | 9 +- src/core/RefreshTokenRequest.ts | 13 +- src/core/TokenCache.ts | 3 + ...ersPartnerMerchantIntegrationGetRequest.ts | 3 +- .../customersPartnerReferralsGetRequest.ts | 3 +- .../customersPartnerReferralsRequest.ts | 6 +- src/customers/types.ts | 5 + src/orders/ordersAuthorizeRequest.ts | 17 +- src/orders/ordersCaptureRequest.ts | 17 +- src/orders/ordersCreateRequest.ts | 24 +- src/orders/ordersGetRequest.ts | 4 +- src/orders/ordersPatchRequest.ts | 28 +- src/orders/ordersValidateRequest.ts | 14 +- src/orders/types.ts | 241 +++++ src/payments/authorizationsCaptureRequest.ts | 26 +- src/payments/authorizationsGetRequest.ts | 6 +- .../authorizationsReauthorizeRequest.ts | 24 +- src/payments/authorizationsVoidRequest.ts | 12 +- src/payments/capturesGetRequest.ts | 5 +- src/payments/capturesRefundRequest.ts | 17 +- src/payments/index.ts | 2 - src/payments/referencedPayoutsItems.ts | 29 - src/payments/refundsGetRequest.ts | 4 +- src/payments/types.ts | 22 + tests/orders/order-utils.ts | 2 +- tests/orders/ordersPatch.spec.ts | 2 +- tsconfig.json | 2 +- yarn.lock | 12 +- 50 files changed, 2093 insertions(+), 210 deletions(-) create mode 100644 .changeset/ten-beds-shout.md delete mode 100644 codegen.cjs create mode 100644 docs/typings/orders/lib.d.ts create mode 100644 docs/typings/payments/lib.d.ts create mode 100644 src/customers/types.ts create mode 100644 src/orders/types.ts delete mode 100644 src/payments/referencedPayoutsItems.ts create mode 100644 src/payments/types.ts diff --git a/.changeset/ten-beds-shout.md b/.changeset/ten-beds-shout.md new file mode 100644 index 0000000..325ae39 --- /dev/null +++ b/.changeset/ten-beds-shout.md @@ -0,0 +1,6 @@ +--- +"paypal-checkout-sdk-samples": patch +"@hyperse-io/paypal-node-sdk": patch +--- + +refactor add request body input typings diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ea1c04c..067175f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -16,7 +16,7 @@ module.exports = { tsconfigRootDir: __dirname, project: 'tsconfig.json', }, - ignorePatterns: [...getDefaultIgnorePatterns()], + ignorePatterns: [...getDefaultIgnorePatterns(), 'docs'], extends: [ '@armit/eslint-config-bases/typescript', '@armit/eslint-config-bases/sonar', diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35760bb..30c6b11 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,15 +62,16 @@ type(scope): Message in present tense `scope` indicates the package affected by the commit: -- common - core -- create +- orders +- payments +- customers - etc. If a commit affects more than one package, separate them with a comma: ``` -fix(core,common): Fix the thing +fix(core,orders): Fix the thing ``` If a commit applies to no particular package (e.g. a tooling change in the root package.json), the scope can be omitted. @@ -97,4 +98,4 @@ Commit messages are linted on commit, so you'll know if your message is not quit ## Setting up the dev environment -After cloning the artmit repo, please follow the [Development guide](https://gitlab.itcjf.com/flatjs-next/bridge/blob/main/README.md#development) in the README for instructions on how to get up and running locally. +After cloning the repo, please follow the [Development guide](https://github.com/hyperse-io/paypal-node-sdk/blob/main/README.md#development) in the README for instructions on how to get up and running locally. diff --git a/cache.config.mjs b/cache.config.mjs index 8841caf..e202b54 100644 --- a/cache.config.mjs +++ b/cache.config.mjs @@ -16,7 +16,7 @@ export const globalCachePath = resolve(`${__dirname}/.cache`); * @returns string */ function sanitize(packageName) { - return packageName.replace('/', '.').replace(/[^a-z0-9.@_-]+/gi, '-'); + return packageName.replace('/', '.').replace(/[^\w.@-]+/g, '-'); } /** diff --git a/codegen.cjs b/codegen.cjs deleted file mode 100644 index 54d8a28..0000000 --- a/codegen.cjs +++ /dev/null @@ -1,44 +0,0 @@ -module.exports = { - overwrite: true, - config: { - strict: true, - namingConvention: { - enumValues: 'keep', - }, - skipTypeNameForRoot: true, - dedupeFragments: true, - inlineFragmentTypes: 'combine', - scalars: { - ID: 'string | number', - Money: 'number', - }, - maybeValue: 'T', - }, - generates: { - 'src/generated-admin-types.ts': { - schema: 'http://localhost:7001/admin-api', - plugins: [ - { - add: { - content: '/* eslint-disable */', - }, - }, - 'typescript', - ], - }, - 'src/generated-shop-types.ts': { - schema: 'http://localhost:7001/shop-api', - plugins: [ - { - add: { - content: '/* eslint-disable */', - }, - }, - 'typescript', - ], - }, - }, - hooks: { - afterAllFileWrite: ['prettier --write'], - }, -}; diff --git a/docs/typings/orders/lib.d.ts b/docs/typings/orders/lib.d.ts new file mode 100644 index 0000000..c96c651 --- /dev/null +++ b/docs/typings/orders/lib.d.ts @@ -0,0 +1,669 @@ +/** + * Docs: https://developer.paypal.com/docs/api/orders/v2/ + */ + +import { + type ActivityTimestamps, + type AddressDetails, + type AddressPortable, + type AmountBreakdown, + type Capture, + type CardBrand, + type CardType, + type LinkDescription, + type Money, + type Name, + type Payee, + type PaymentInstruction, + type Phone, + type ProcessorResponse, + type Refund, + type ShippingType, + type Status, + type TaxInfo, + type Token, +} from '../payments/lib'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-account_tier +export type AccountTier = 'BUSINESS' | 'PERSONAL' | 'PREMIER'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-ach_debit_response +export interface AchDebitResponse { + account_holder_name: string; + last_digits: string; + routing_number: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-address_name +export interface AddressName { + address_details?: AddressDetails; + address_line_1?: string; + address_line_2?: string; + address_line_3?: string; + addressee?: string; + admin_area_1?: string; + admin_area_2?: string; + admin_area_3?: string; + admin_area_4?: string; + country_code: string; + postal_code?: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-amount_with_breakdown +export interface AmountWithBreakdown { + breakdown?: AmountBreakdown; + currency_code: string; + value: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-authentication_response +export interface AuthenticationResponse { + liability_shift: LiabilityShift; + three_d_secure: ThreeDSecureAuthenticationResponse; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-three_d_secure_authentication_response +export interface ThreeDSecureAuthenticationResponse { + authentication_status: AuthenticationStatus; + enrollment_status: EnrollmentStatus; +} + +export type AuthenticationStatus = + | 'Y' + | 'N' + | 'U' + | 'A' + | 'C' + | 'R' + | 'D' + | 'I'; + +export type EnrollmentStatus = 'Y' | 'N' | 'U' | 'B'; + +export type LiabilityShift = 'NO' | 'POSSIBLE' | 'UNKNOWN' | 'YES'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-business_name +export interface BusinessName { + business_name: string; + orthography: Orthography; +} + +export type Orthography = + | 'Arab' + | 'Armn' + | 'Beng' + | 'Cans' + | 'Cyrl' + | 'Deva' + | 'Ethi' + | 'Geor' + | 'Grek' + | 'Gujr' + | 'Guru' + | 'Hani' + | 'Hebr' + | 'Java' + | 'Jpan' + | 'Kana' + | 'Khmr' + | 'Knda' + | 'Kore' + | 'Laoo' + | 'Latn' + | 'Mlym' + | 'Mong' + | 'Mymr' + | 'Orya' + | 'Sinh' + | 'Sund' + | 'Syrc' + | 'Taml' + | 'Telu' + | 'Thaa' + | 'Thai' + | 'Tibt' + | 'Yiii' + | 'Zyyy' + | 'Zzzz'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-business_type +export type business_type = + | 'ANY_OTHER_BUSINESS_ENTITY' + | 'ASSOCIATION' + | 'CORPORATION' + | 'GENERAL_PARTNERSHIP' + | 'GOVERNMENT' + | 'INDIVIDUAL' + | 'LIMITED_LIABILITY_PARTNERSHIP' + | 'LIMITED_LIABILITY_PRIVATE_CORPORATION' + | 'LIMITED_LIABILITY_PROPRIETORS' + | 'LIMITED_PARTNERSHIP' + | 'LIMITED_PARTNERSHIP_PRIVATE_CORPORATION' + | 'NONPROFIT' + | 'ONLY_BUY_OR_SEND_MONEY' + | 'OTHER_CORPORATE_BODY' + | 'PARTNERSHIP' + | 'PRIVATE_CORPORATION' + | 'PRIVATE_PARTNERSHIP' + | 'PROPRIETORSHIP' + | 'PROPRIETORSHIP_CRAFTSMAN' + | 'PROPRIETORY_COMPANY' + | 'PUBLIC_COMPANY' + | 'PUBLIC_CORPORATION' + | 'PUBLIC_PARTNERSHIP' + | 'REGISTERED_COOPERATIVE'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-card_response +export interface CardResponse { + billing_address: { + address_line_1?: string; + address_line_2?: string; + admin_area_1?: string; + admin_area_2?: string; + country_code: string; + postal_code?: string; + }; + authentication_result: AuthenticationResponse; + brand: CardBrand; + last_digits: string; + name: string; + type: CardType; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-checkout_payment_intent +export type CheckoutPaymentIntent = 'CAPTURE' | 'AUTHORIZE'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-confirm_order_request +export interface ConfirmOrderRequest { + application_context?: OrderConfirmApplicationContext; + payment_source: PaymentSource; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-order_confirm_application_context +export interface OrderConfirmApplicationContext { + brand_name: string; + cancel_url: string; + locale: string; + return_url: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_source +export interface PaymentSource { + token: Token; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-contingency +export type Contingency = '3D_SECURE'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-document_issuer +export interface DocumentIssuer { + authority?: string; + country_code: string; + province_code?: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-enrolled +export type Enrolled = 'B' | 'N' | 'U' | 'Y'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-identity_document +export interface IdentityDocument { + type: IdentityDocumentType; + issuer: DocumentIssuer; + id_number: string; + issued_date: string; + expiration_date: string; +} + +export type IdentityDocumentType = + | 'INDIVIDUAL_TAXPAYER_IDENTIFICATION_NUMBER' + | 'NATIONAL_IDENTIFICATION_NUMBER' + | 'PASSPORT_NUMBER' + | 'SOCIAL_SECURITY_NUMBER' + | 'SSN4' + | 'TAX_IDENTIFICATION_NUMBER'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-issuer +export type Issuer = 'CARD_ISSUER_INSTALLMENTS' | 'PAYPAL'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-account +export interface ModelAccount { + account_id: string; + account_number: string; + account_tags: string[]; + legal_country_code: string; + legal_entity: string; + pricing_category: string; + registration_type: string; + status: Status; + tier: Tier; + time_created: string; +} + +export type Tier = 'BUSINESS' | 'PERSONAL' | 'PREMIER'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-address_with_confirmation +export interface ModelAddressWithConfirmation { + confirmation_authority: string; + confirmation_status: string; + id: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-auth_tolerance +export interface ModelAuthTolerance { + absolute: Money; + percent: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-authorization_directives +export interface ModelAuthorizationDirectives { + allow_multiple_captures: boolean; + expiry_time_offset: number; + honor_time_offset: number; + tolerance: ModelAuthTolerance; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-business +export interface ModelBusiness extends ActivityTimestamps { + addresses: ModelAddressWithConfirmation[]; + category: ModelBusinessCategory; + customer_service_contactsobject: ModelCustomerServiceContact; + description: string; + emails: string[]; + external_id: string; + id: string; + identifications: ModelBusinessIdentification; + names: BusinessName[]; + owners: ModelPerson[]; + phones: ModelPhoneInfo[]; + primary_email: string; + primary: boolean; + type: 'INDIVIDUAL' | 'PROPRIETORSHIP' | 'PARTNERSHIP'; + url: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-business_category +export interface ModelBusinessCategory { + category: string; + mcc_code: string; + sub_category: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-business_identification +export interface ModelBusinessIdentification { + identifier: string; + issued_time: string; + issuer: DocumentIssuer; + type: 'TAX_IDENTIFICATION_NUMBER' | 'BUSINESS_REGISTRATION_NUMBER'; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-customer_service_contact +export interface ModelCustomerServiceContact { + emails: string[]; + phones: ModelPhoneInfo[]; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-currency_receiving_type +export type ModelEnumsCurrencyReceivingType = + | 'ACCEPT' + | 'ACCEPT_OPEN' + | 'DENY' + | 'HOLD'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-disbursement_type +export type ModelEnumsDisbursementType = 'INSTANT' | 'DELAYED'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-facilitator_type +export type ModelEnumsFacilitatorType = 'API_CALLER' | 'INTERNAL' | 'PARTNER'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-liability_type +export type ModelEnumsLiabilityType = 'FULL' | 'PARTIAL'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-participant_type +export type ModelEnumsParticipantType = 'FACILITATOR' | 'RECEIVER' | 'SENDER'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-enums-pricing_type +export type ModelEnumsPricingType = 'BLENDED' | 'IC_PLUS'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-business +export interface ModelPerson extends ActivityTimestamps { + id: string; + external_id: string; + primary: boolean; + primary_email: string; + emails: string[]; + phones: ModelPhoneInfo[]; + addresses: ModelAddressWithConfirmation[]; + names: string[]; + citizenship: string; + birth_date: string; + identifications: IdentityDocument; +} + +// https://developer.paypal.com/api/orders/v2/#definition-order +export interface Order extends ActivityTimestamps { + id: string; + intent: string; + links: LinkDescription[]; + payer: Payer; + payment_source: PaymentSourceResponse; + purchase_units: PurchaseUnit[]; + status: Status; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-model-phone_info +export interface ModelPhoneInfo { + phone_number: Phone; + phone_type: PhoneType; +} + +export type PhoneType = 'FAX' | 'HOME' | 'MOBILE' | 'OTHER' | 'PAGER' | 'WORK'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payer_base +export interface PayerBase { + email_address: string; + payer_id: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payer +export interface Payer extends PayerBase { + address: AddressPortable; + birth_date: string; + name: Name; + phone: PhoneWithType; + tax_info: TaxInfo; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-phone_with_type +export interface PhoneWithType { + phone_type?: PhoneType; + phone_number: { + national_number: string; + }; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit +export interface PurchaseUnit { + amount: AmountWithBreakdown; + custom_id: string; + description: string; + id: string; + invoice_id: string; + items: Item[]; + payee: Payee; + payment_instruction: PaymentInstruction; + payments: PaymentCollection; + reference_id: string; + shipping: ShippingDetail; + soft_descriptor: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request +export interface PurchaseUnitRequest { + amount: AmountWithBreakdown; + custom_id?: string; + description?: string; + invoice_id?: string; + items?: Item[]; + payee?: Payee; + payment_instruction?: PaymentInstruction; + reference_id?: string; + shipping?: ShippingDetail; + soft_descriptor?: string; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-item +export interface Item { + name: string; + unit_amount: Money; + tax?: Money; + quantity: string; + description?: string; + sku?: string; + category: Category; +} + +export type Category = 'DIGITAL_GOODS' | 'PHYSICAL_GOODS' | 'DONATION'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-shipping_detail +export interface ShippingDetail { + address: { + address_line_1?: string; + address_line_2?: string; + admin_area_1?: string; + admin_area_2?: string; + country_code: string; + postal_code?: string; + }; + name?: { + full_name?: string; + }; + type?: ShippingType; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_collection +export interface PaymentCollection { + authorizations: AuthorizationWithAdditionalData; + captures: Capture[]; + refunds: Refund[]; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-authorization_with_additional_data +export interface AuthorizationWithAdditionalData { + processor_response: ProcessorResponse; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_source_response +export interface PaymentSourceResponse { + card: CardResponse; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context +export interface OrderApplicationContext { + brand_name?: string; + locale?: string; + landing_page?: LandingPage; + shipping_preference?: ShippingPreference; + user_action?: UserAction; + payment_method?: PaymentMethod; + return_url?: string; + cancel_url?: string; + stored_payment_source?: StoredPaymentSource; +} + +export type LandingPage = 'LOGIN' | 'BILLING' | 'NO_PREFERENCE'; + +export type ShippingPreference = + | 'GET_FROM_FILE' + | 'NO_SHIPPING' + | 'SET_PROVIDED_ADDRESS'; + +export type UserAction = 'CONTINUE' | 'PAY_NOW'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_method +export interface PaymentMethod { + payee_preferred: PayeePreferred; + payer_selected: string; + standard_entry_class_code: StandardEntryClassCode; +} + +export type PayeePreferred = 'IMMEDIATE_PAYMENT_REQUIRED' | 'UNRESTRICTED'; + +export type StandardEntryClassCode = 'CCD' | 'PPD' | 'TEL' | 'WEB'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-stored_payment_source +export interface StoredPaymentSource { + payment_initiator: PaymentInitiator; + payment_type: PaymentType; + usage?: Usage; + previous_network_transaction_reference?: object; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_initiator +export type PaymentInitiator = 'CUSTOMER' | 'MERCHANT'; + +export type PaymentType = 'ONE_TIME' | 'RECURRING' | 'UNSCHEDULED'; + +export type Usage = 'DERIVED' | 'FIRST' | 'SUBSEQUENT'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-patch +export interface Patch { + from: string; + op: Operation; + path: string; + value: any; +} + +export type Operation = 'add' | 'copy' | 'move' | 'remove' | 'replace' | 'test'; + +export interface BaseOrderHeaders { + Authorization: string; + 'Content-Type': 'application/json'; +} + +export class BaseOrderRequest { + readonly path: string; + readonly verb: + | 'CONNECT' + | 'DELETE' + | 'GET' + | 'HEAD' + | 'OPTIONS' + | 'PATCH' + | 'POST' + | 'PUT'; + readonly body: B; + readonly headers: H; + + constructor(orderId: string); +} + +/** + * Orders Authorize + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_authorize} + */ +export namespace OrdersAuthorize { + interface RequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; + } + + interface RequestData { + payment_source: PaymentSource; + } +} + +export class OrdersAuthorizeRequest extends BaseOrderRequest< + OrdersAuthorize.RequestHeaders, + Order +> { + payPalClientMetadataId(payPalClientMetadataId: string): this; + + payPalRequestId(payPalRequestId: string): this; + + prefer(prefer: string): this; + + requestBody(body: OrdersAuthorize.RequestData): this; +} + +/** + * Orders Capture + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_capture} + */ +export namespace OrdersCapture { + interface RequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; + } + + interface RequestData { + payment_source: PaymentSource; + } +} + +export class OrdersCaptureRequest extends BaseOrderRequest< + OrdersCapture.RequestHeaders, + Order +> { + payPalClientMetadataId(payPalClientMetadataId: string): this; + + payPalRequestId(payPalRequestId: string): this; + + prefer(prefer: string): this; + + requestBody(body: OrdersCapture.RequestData): this; +} + +/** + * Orders Create + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_create} + */ +export namespace OrdersCreate { + interface RequestHeaders extends BaseOrderHeaders { + 'PayPal-Partner-Attribution-Id'?: string; + Prefer?: string; + } + + interface RequestData { + intent: CheckoutPaymentIntent; + payer?: Payer; + purchase_units: PurchaseUnitRequest[]; + application_context?: OrderApplicationContext; + } +} + +export class OrdersCreateRequest extends BaseOrderRequest< + OrdersCreate.RequestHeaders, + Order +> { + constructor(); + + payPalPartnerAttributionId(payPalPartnerAttributionId: string): this; + + prefer(prefer: string): this; + + requestBody(order: OrdersCreate.RequestData): this; +} + +/** + * Orders Get + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_get} + */ +export namespace OrdersGet { + type RequestHeaders = BaseOrderHeaders; +} + +export class OrdersGetRequest extends BaseOrderRequest< + OrdersGet.RequestHeaders, + Order +> {} + +/** + * Orders Patch + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_patch} + */ +export namespace OrdersPatch { + type RequestHeaders = BaseOrderHeaders; + + type RequestData = Patch[]; +} + +export class OrdersPatchRequest extends BaseOrderRequest { + requestBody(body: OrdersPatch.RequestData): this; +} + +/** + * Orders Validate + */ +export namespace OrdersValidate { + interface RequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; + } +} + +export class OrdersValidateRequest extends BaseOrderRequest { + payPalClientMetadataId(payPalClientMetadataId: string): this; + + requestBody(body: object): this; +} diff --git a/docs/typings/payments/lib.d.ts b/docs/typings/payments/lib.d.ts new file mode 100644 index 0000000..85ebb35 --- /dev/null +++ b/docs/typings/payments/lib.d.ts @@ -0,0 +1,858 @@ +/** + * Docs: https://developer.paypal.com/docs/api/orders/v2/ + */ + +// https://developer.paypal.com/docs/api/payments/v2/#definition-ach_debit +export interface AchDebit { + account_holder_name: string; + account_number: string; + account_type?: AccountType; + routing_number: string; +} + +export type AccountType = 'CHECKING' | 'SAVINGS'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-activity_timestamps +export interface ActivityTimestamps { + create_time: string; + update_time: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-address_details +export interface AddressDetails { + building_name: string; + delivery_service: string; + street_name: string; + street_number: string; + street_type: string; + sub_building: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-address_portable +export interface AddressPortable { + address_details?: AddressDetails; + address_line_1?: string; + address_line_2?: string; + address_line_3?: string; + admin_area_1?: string; + admin_area_2?: string; + admin_area_3?: string; + admin_area_4?: string; + country_code: string; + postal_code?: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-amount_breakdown +export interface AmountBreakdown { + discount: Money; + handling: Money; + insurance: Money; + item_total: Money; + shipping_discount: Money; + shipping: Money; + tax_total: Money; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-authorization +export interface Authorization extends ActivityTimestamps, AuthorizationStatus { + amount: Money; + custom_id: string; + expiration_time: string; + id: string; + invoice_id: string; + links: LinkDescription[]; + seller_protection: SellerProtection; +} + +export type Status = + | 'CANCELLED' + | 'CAPTURED' + | 'COMPLETED' + | 'CREATED' + | 'DECLINED' + | 'DENIED' + | 'ELIGIBLE' + | 'EXPIRED' + | 'FAILED' + | 'NOT_ELIGIBLE' + | 'PARTIALLY_CAPTURED' + | 'PARTIALLY_CREATED' + | 'PARTIALLY_ELIGIBLE' + | 'PARTIALLY_REFUNDED' + | 'PENDING' + | 'REFUNDED' + | 'VOIDED'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-authorization_status +export interface AuthorizationStatus { + readonly status_details: AuthorizationStatusDetails; + readonly status: Status; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-authorization_status_details +export interface AuthorizationStatusDetails { + reason: Reason; +} + +export type Reason = + | 'BUYER_COMPLAINT' + | 'CHARGEBACK' + | 'ECHECK' + | 'INTERNATIONAL_WITHDRAWAL' + | 'OTHER' + | 'PENDING_REVIEW' + | 'RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION' + | 'REFUNDED' + | 'TRANSACTION_APPROVED_AWAITING_FUNDING' + | 'UNILATERAL' + | 'VERIFICATION_REQUIRED'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-capture +export interface Capture extends ActivityTimestamps, CaptureStatus { + amount: Money; + custom_id: string; + disbursement_mode: DisbursementMode; + final_capture: boolean; + id: string; + invoice_id: string; + links: LinkDescription[]; + processor_response: ProcessorResponse; + seller_protection: SellerProtection; + seller_receivable_breakdown: SellerReceivableBreakdown; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-capture_request +export interface CaptureRequest { + amount: Money; + final_capture: boolean; + invoice_id: string; + note_to_payer: string; + payment_instruction?: PaymentInstruction; + soft_descriptor: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status +export interface CaptureStatus { + readonly status_details: CaptureStatusDetails; + readonly status: Status; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status_details +export interface CaptureStatusDetails { + reason: Reason; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-card +export interface Card { + billing_address?: { + address_line_1?: string; + address_line_2?: string; + admin_area_1?: string; + admin_area_2?: string; + country_code: string; + postal_code?: string; + }; + brand?: CardBrand; + card_type?: CardBrand; + expiry: string; + id?: string; + last_digits?: string; + name?: string; + number: string; + security_code?: string; + type?: CardType; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-card_brand +export type CardBrand = + | 'AMEX' + | 'CB_NATIONALE' + | 'CETELEM' + | 'CHINA_UNION_PAY' + | 'CONFIDIS' + | 'CONFIGOGA' + | 'DELTA' + | 'DISCOVER' + | 'ELECTRON' + | 'JCB' + | 'MAESTRO' + | 'MASTERCARD' + | 'SOLO' + | 'STAR' + | 'SWITCH' + | 'VISA'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-card_type +export type CardType = 'CREDIT' | 'DEBIT' | 'PREPAID' | 'STORE' | 'UNKNOWN'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-disbursement_mode +export type DisbursementMode = 'DELAYED' | 'INSTANT'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-dispute_category +export type DisputeCategory = 'ITEM_NOT_RECEIVED' | 'UNAUTHORIZED_TRANSACTION'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-error +export interface Error { + debug_id: string; + details?: ErrorDetails[]; + information_link?: string; + links?: LinkDescription[]; + message: string; + name: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-error_details +export interface ErrorDetails { + description?: string; + field?: string; + issue: string; + location?: string; + value?: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-exchange_rate +export interface ExchangeRate { + source_currency: string; + target_currency: string; + value: string; +} + +// vhttps://developer.paypal.com/docs/api/payments/v2/#definition-link_description +export interface LinkDescription { + href: string; + method?: Method; + rel: string; +} + +export type Method = + | 'CONNECT' + | 'DELETE' + | 'GET' + | 'HEAD' + | 'OPTIONS' + | 'PATCH' + | 'POST' + | 'PUT'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-money +export interface Money { + currency_code: string; + value: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-name +export interface Name { + alternate_full_name: string; + full_name: string; + given_name: string; + middle_name: string; + prefix: string; + suffix: string; + surname: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-net_amount_breakdown +export interface NetAmountBreakdown { + converted_amount: Money; + exchange_rate: ExchangeRate; + payable_amount: Money; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payee +export interface Payee { + email_address?: string; + merchant_id?: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payee_base +export type PayeeBase = Payee; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction +export interface PaymentInstruction { + disbursement_mode: DisbursementMode; + payee_pricing_tier_id: string; + platform_fees: PlatformFee[]; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-phone +export interface Phone { + country_code: string; + extension_number?: string; + national_number: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee +export interface PlatformFee { + amount: Money; + payee?: PayeeBase; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-processor_response +export interface ProcessorResponse { + readonly avs_code: AVSCode; + readonly cvv_code: CVVCode; + readonly payment_advice_code: PaymentAdviceCode; + readonly response_code: ResponseCode; +} + +export type AVSCode = + | 'A' + | 'B' + | 'C' + | 'D' + | 'E' + | 'F' + | 'G' + | 'I' + | 'M' + | 'N' + | 'P' + | 'R' + | 'S' + | 'U' + | 'W' + | 'X' + | 'Y' + | 'Z' + /** MAESTRO_NOT_RESPONSE */ + | 'Null' + /** MAESTRO_ALL_MATCHES */ + | '0' + /** MAESTRO_NONE_MATCHES */ + | '1' + /** MAESTRO_PART_MATCHES */ + | '2' + /** MAESTRO_NOT_PROCESSED */ + | '3' + /** MAESTRO_NOT_AVAILABLE */ + | '4'; + +export type CVVCode = + | 'E' + | 'I' + | 'M' + | 'N' + | 'P' + | 'S' + | 'U' + | 'X' + /** ALL_OTHERS */ + | 'All others' + /** Maestro_matched */ + | '0' + /** Maestro_not_match */ + | '1' + /** Maestro_not_implemented */ + | '2' + /** Maestro_not_present */ + | '3' + /** Maestro_not_available */ + | '4'; + +export type ResponseCode = + /** APPROVED */ + | '0000' + /** REFERRAL */ + | '0100' + /** BAD_RESPONSE_REVERSAL_REQUIRED */ + | '0800' + /** PARTIAL_AUTHORIZATION */ + | '1000' + /** INVALID_DATA_FORMAT */ + | '1300' + /** INVALID_AMOUNT */ + | '1310' + /** INVALID_TRANSACTION_CARD_ISSUER_ACQUIRER */ + | '1312' + /** INVALID_CAPTURE_DATE */ + | '1317' + /** INVALID_CURRENCY_CODE */ + | '1320' + /** INVALID_ACCOUNT */ + | '1330' + /** INVALID_ACCOUNT_RECURRING */ + | '1335' + /** INVALID_TERMINAL */ + | '1340' + /** INVALID_MERCHANT */ + | '1350' + /** BAD_PROCESSING_CODE */ + | '1360' + /** INVALID_MCC */ + | '1370' + /** INVALID_EXPIRATION */ + | '1380' + /** INVALID_CARD_VERIFICATION_VALUE */ + | '1382' + /** INVALID_LIFE_CYCLE_OF_TRANSACTION */ + | '1384' + /** INVALID_ORDER */ + | '1390' + /** TRANSACTION_CANNOT_BE_COMPLETED */ + | '1393' + /** DO_NOT_HONOR */ + | '0500' + /** GENERIC_DECLINE */ + | '5100' + /** CVV2_FAILURE */ + | '5110' + /** INSUFFICIENT_FUNDS */ + | '5120' + /** INVALID_PIN */ + | '5130' + /** CARD_CLOSED */ + | '5140' + /** PICKUP_CARD_SPECIAL_CONDITIONS */ + | '5150' + /** UNAUTHORIZED_USER */ + | '5160' + /** AVS_FAILURE */ + | '5170' + /** INVALID_OR_RESTRICTED_CARD */ + | '5180' + /** SOFT_AVS */ + | '5190' + /** DUPLICATE_TRANSACTION */ + | '5200' + /** INVALID_TRANSACTION */ + | '5210' + /** EXPIRED_CARD */ + | '5400' + /** INCORRECT_PIN_REENTER */ + | '5500' + /** TRANSACTION_NOT_PERMITTED */ + | '5700' + /** REVERSAL_REJECTED */ + | '5800' + /** INVALID_ISSUE */ + | '5900' + /** ISSUER_NOT_AVAILABLE_NOT_RETRIABLE */ + | '5910' + /** ISSUER_NOT_AVAILABLE_RETRIABLE */ + | '5920' + /** ACCOUNT_NOT_ON_FILE */ + | '6300' + /** APPROVED_NON_CAPTURE */ + | '7600' + /** ERROR_3DS */ + | '7700' + /** AUTHENTICATION_FAILED */ + | '7710' + /** BIN_ERROR */ + | '7800' + /** PIN_ERROR */ + | '7900' + /** PROCESSOR_SYSTEM_ERROR */ + | '8000' + /** HOST_KEY_ERROR */ + | '8010' + /** CONFIGURATION_ERROR */ + | '8020' + /** UNSUPPORTED_OPERATION */ + | '8030' + /** FATAL_COMMUNICATION_ERROR */ + | '8100' + /** RETRIABLE_COMMUNICATION_ERROR */ + | '8110' + /** SYSTEM_UNAVAILABLE */ + | '8220' + /** DECLINED_PLEASE_RETRY */ + | '9100' + /** SUSPECTED_FRAUD */ + | '9500' + /** SECURITY_VIOLATION */ + | '9510' + /** LOST_OR_STOLEN */ + | '9520' + /** HOLD_CALL_CENTER */ + | '9530' + /** REFUSED_CARD */ + | '9540' + /** UNRECOGNIZED_RESPONSE_CODE */ + | '9600' + /** CARD_NOT_ACTIVATED */ + | '5930' + /** PPMD */ + | 'PPMD' + /** CE_REGISTRATION_INCOMPLETE */ + | 'PPCE' + /** NETWORK_ERROR */ + | 'PPNT' + /** CARD_TYPE_UNSUPPORTED */ + | 'PPCT' + /** TRANSACTION_TYPE_UNSUPPORTED */ + | 'PPTT' + /** CURRENCY_USED_INVALID */ + | 'PPCU' + /** QUASI_CASH_UNSUPPORTED */ + | 'PPQC' + /** VALIDATION_ERROR */ + | 'PPVE' + /** VIRTUAL_TERMINAL_UNSUPPORTED */ + | 'PPVT' + /** DCC_UNSUPPORTED */ + | 'PPDC' + /** INTERNAL_SYSTEM_ERROR */ + | 'PPER' + /** ID_MISMATCH */ + | 'PPIM' + /** H1_ERROR */ + | 'PPH1' + /** STATUS_DESCRIPTION */ + | 'PPSD' + /** ADULT_GAMING_UNSUPPORTED */ + | 'PPAG' + /** LARGE_STATUS_CODE */ + | 'PPLS' + /** COUNTRY */ + | 'PPCO' + /** BILLING_ADDRESS */ + | 'PPAD' + /** MCC_CODE */ + | 'PPAU' + /** CURRENCY_CODE_UNSUPPORTED */ + | 'PPUC' + /** UNSUPPORTED_REVERSAL */ + | 'PPUR' + /** VALIDATE_CURRENCY */ + | 'PPVC' + /** BANKAUTH_ROW_MISMATCH */ + | 'PPS0' + /** BANKAUTH_ROW_SETTLED */ + | 'PPS1' + /** BANKAUTH_ROW_VOIDED */ + | 'PPS2' + /** BANKAUTH_EXPIRED */ + | 'PPS3' + /** CURRENCY_MISMATCH */ + | 'PPS4' + /** CREDITCARD_MISMATCH */ + | 'PPS5' + /** AMOUNT_MISMATCH */ + | 'PPS6' + /** INVALID_PARENT_TRANSACTION_STATUS */ + | 'PPRF' + /** EXPIRY_DATE */ + | 'PPEX' + /** AMOUNT_EXCEEDED */ + | 'PPAX' + /** AUTH_MESSAGE */ + | 'PPDV' + /** DINERS_REJECT */ + | 'PPDI' + /** AUTH_RESULT */ + | 'PPAR' + /** BAD_GAMING */ + | 'PPBG' + /** GAMING_REFUND_ERROR */ + | 'PPGR' + /** CREDIT_ERROR */ + | 'PPCR' + /** AMOUNT_INCOMPATIBLE */ + | 'PPAI' + /** IDEMPOTENCY_FAILURE */ + | 'PPIF' + /** BLOCKED_Mastercard */ + | 'PPMC' + /** AMEX_DISABLED */ + | 'PPAE' + /** FIELD_VALIDATION_FAILED */ + | 'PPFV' + /** INVALID_INPUT_FAILURE */ + | 'PPII' + /** INVALID_PAYMENT_METHOD */ + | 'PPPM' + /** USER_NOT_AUTHORIZED */ + | 'PPUA' + /** INVALID_FUNDING_INSTRUMENT */ + | 'PPFI' + /** EXPIRED_FUNDING_INSTRUMENT */ + | 'PPEF' + /** RESTRICTED_FUNDING_INSTRUMENT */ + | 'PPFR' + /** EXCEEDS_FREQUENCY_LIMIT */ + | 'PPEL' + /** CVV_FAILURE */ + | 'PCVV' + /** INVALID_VERIFICATION_TOKEN */ + | 'PPTV' + /** VERIFICATION_TOKEN_EXPIRED */ + | 'PPTE' + /** INVALID_PRODUCT */ + | 'PPPI' + /** INVALID_TRACE_ID */ + | 'PPIT' + /** INVALID_TRACE_REFERENCE */ + | 'PPTF' + /** FUNDING_SOURCE_ALREADY_EXISTS */ + | 'PPFE' + /** VERIFICATION_TOKEN_REVOKED */ + | 'PPTR' + /** INVALID_TRANSACTION_ID */ + | 'PPTI' + /** SECURE_ERROR_3DS */ + | 'PPD3' + /** NO_PHONE_FOR_DCC_TRANSACTION */ + | 'PPPH' + /** ARC_AVS */ + | 'PPAV' + /** ARC_CVV */ + | 'PPC2' + /** LATE_REVERSAL */ + | 'PPLR' + /** NOT_SUPPORTED_NRC */ + | 'PPNC' + /** MERCHANT_NOT_REGISTERED */ + | 'PPRR' + /** ARC_SCORE */ + | 'PPSC' + /** AMEX_DENIED */ + | 'PPSE' + /** UNSUPPORT_ENTITY */ + | 'PPUE' + /** UNSUPPORT_INSTALLMENT */ + | 'PPUI' + /** UNSUPPORT_POS_FLAG */ + | 'PPUP' + /** UNSUPPORT_REFUND_ON_PENDING_BC */ + | 'PPRE'; + +export type PaymentAdviceCode = + /** MASTERCARD_EXPIRED */ + | '01' + /** MASTERCARD_CREDIT_LIMIT */ + | '02' + /** MASTERCARD_ACCOUNT_CLOSED */ + | '03' + /** MASTERCARD_UNSUCCESSFUL */ + | '21'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-reauthorize_request +export interface ReauthorizeRequest { + amount: Money; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-refund +export interface Refund extends ActivityTimestamps, RefundStatus { + amount: Money; + id: string; + invoice_id: string; + links: LinkDescription[]; + note_to_payer: string; + seller_payable_breakdown: SellerPayableBreakdown; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-refund_request +export interface RefundRequest { + amont: Money; + invoice_id: string; + note_to_payer: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-refund_status +export interface RefundStatus { + readonly status_details: RefundStatusDetails; + readonly status: Status; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-refund_status_details +export interface RefundStatusDetails { + reason: Reason; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-seller_payable_breakdown +export interface SellerPayableBreakdown { + gross_amount: Money; + net_amount_breakdown: NetAmountBreakdown[]; + net_amount_in_receivable_currency: Money; + net_amount: Money; + paypal_fee_in_receivable_currency: Money; + paypal_fee: Money; + platform_fees: PlatformFee[]; + total_refunded_amount: Money; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-seller_protection +export interface SellerProtection { + readonly dispute_categories: DisputeCategory[]; + readonly status: Status; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-seller_receivable_breakdown +export interface SellerReceivableBreakdown { + exchange_rate?: ExchangeRate; + gross_amount: Money; + net_amount?: Money; + paypal_fee_in_receivable_currency?: Money; + paypal_fee?: Money; + platform_fees?: PlatformFee[]; + receivable_amount?: Money; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-shipping_type +export type ShippingType = 'PICKUP' | 'PICKUP_IN_PERSON' | 'SHIPPING'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-supplementary_purchase_data +export interface SupplementaryPurchaseData { + invoice_id: string; + note_to_payer: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-tax_info +export interface TaxInfo { + tax_id_type: TaxIdType; + tax_id: string; +} + +export type TaxIdType = 'BR_CNPJ' | 'BR_CPF'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-token +export interface Token { + id: string; + type: TokenType; +} + +export type TokenType = 'BILLING_AGREEMENT'; + +export interface BasePaymentHeaders { + Authorization: string; + 'Content-Type': 'application/json'; +} + +export class BasePaymentRequest { + readonly path: string; + readonly verb: + | 'CONNECT' + | 'DELETE' + | 'GET' + | 'HEAD' + | 'OPTIONS' + | 'PATCH' + | 'POST' + | 'PUT'; + readonly body: D; + readonly headers: H; + + constructor(authorizationId: string); +} + +/** + * Authorizations Capture + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_capture} + */ +export namespace AuthorizationsCapture { + interface RequestHeaders extends BasePaymentHeaders { + 'PayPal-Request-Id'?: string; + Prefer?: string; + } +} + +export class AuthorizationsCaptureRequest extends BasePaymentRequest< + AuthorizationsCapture.RequestHeaders, + Capture +> { + payPalRequestId(payPalRequestId: string): this; + + prefer(prefer: string): this; + + requestBody(body: CaptureRequest): this; +} + +/** + * Authorizations Get + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_get} + */ +export class AuthorizationsGetRequest extends BasePaymentRequest< + BasePaymentHeaders, + Capture +> {} + +/** + * Authorizations Reauthorize + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_reauthorize} + */ +export namespace AuthorizationsReauthorize { + interface RequestHeaders extends BasePaymentHeaders { + 'PayPal-Request-Id'?: string; + Prefer?: string; + } + + interface RequestData { + amount: Money; + } +} + +export class AuthorizationsReauthorizeRequest extends BasePaymentRequest< + AuthorizationsReauthorize.RequestHeaders, + Capture +> { + payPalRequestId(payPalRequestId: string): this; + + prefer(prefer: string): this; + + requestBody(body: AuthorizationsReauthorize.RequestData): this; +} + +/** + * Authorizations Void + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_void} + */ +export namespace AuthorizationsVoid { + interface RequestHeaders extends BasePaymentHeaders { + 'PayPal-Auth-Assertion'?: string; + Prefer?: string; + } +} + +export class AuthorizationsVoidRequest extends BasePaymentRequest {} + +/** + * Captures Get + * @see {@link https://developer.paypal.com/api/payments/v2/#captures_get} + */ +export class CapturesGetRequest extends BasePaymentRequest< + BasePaymentHeaders, + Capture +> {} + +/** + * Captures Refund + * @see {@link https://developer.paypal.com/api/payments/v2/#captures_refund} + */ +export namespace CapturesRefund { + interface RequestHeaders extends BasePaymentHeaders { + 'PayPal-Auth-Assertion'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; + } + + interface RequestData { + amount: Money; + invoice_id: string; + note_to_payer: string; + } +} + +export class CapturesRefundRequest extends BasePaymentRequest< + CapturesRefund.RequestHeaders, + Capture +> { + constructor(captureId: string); + + payPalRequestId(payPalRequestId: string): this; + + prefer(prefer: string): this; + + requestBody(body: CapturesRefund.RequestData): this; +} + +/** + * Refunds Get + * @see {@link https://developer.paypal.com/api/payments/v2/#refunds_get} + */ +export class RefundsGetRequest extends BasePaymentRequest< + BasePaymentHeaders, + Capture +> { + constructor(refundId: string); +} diff --git a/package.json b/package.json index 799595e..567b4af 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ }, "dependencies": { "@paypal/paypalhttp": "^1.0.1", + "@types/paypal__checkout-server-sdk": "^1.0.8", "@types/paypal__paypalhttp": "^1.0.3" }, "devDependencies": { diff --git a/samples/AuthorizeIntentExamples/authorizeOrder.ts b/samples/AuthorizeIntentExamples/authorizeOrder.ts index 4f5e47f..b1451ba 100644 --- a/samples/AuthorizeIntentExamples/authorizeOrder.ts +++ b/samples/AuthorizeIntentExamples/authorizeOrder.ts @@ -1,4 +1,4 @@ -import { OrdersAuthorizeRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient } from 'samples/Common/payPalClient.js'; /** @@ -11,7 +11,7 @@ import { createClient } from 'samples/Common/payPalClient.js'; */ export async function authorizeOrder(orderId, debug = false) { try { - const request = new OrdersAuthorizeRequest(orderId); + const request = new orders.OrdersAuthorizeRequest(orderId); request.requestBody({}); const response = await createClient().execute(request); if (debug) { diff --git a/samples/AuthorizeIntentExamples/captureOrder.ts b/samples/AuthorizeIntentExamples/captureOrder.ts index 2c86b92..df1f0f7 100644 --- a/samples/AuthorizeIntentExamples/captureOrder.ts +++ b/samples/AuthorizeIntentExamples/captureOrder.ts @@ -1,4 +1,4 @@ -import { AuthorizationsCaptureRequest } from '@hyperse-io/paypal-node-sdk'; +import { payments } from '@hyperse-io/paypal-node-sdk'; import { createClient } from 'samples/Common/payPalClient.js'; /** @@ -11,8 +11,8 @@ import { createClient } from 'samples/Common/payPalClient.js'; */ export async function captureOrder(authId, debug = false) { try { - const request = new AuthorizationsCaptureRequest(authId); - request.requestBody({}); + const request = new payments.AuthorizationsCaptureRequest(authId); + request.requestBody({} as any); const response = await createClient().execute(request); if (debug) { console.log('Status Code: ' + response.statusCode); diff --git a/samples/AuthorizeIntentExamples/createOrder.ts b/samples/AuthorizeIntentExamples/createOrder.ts index 57d42ac..f851d76 100644 --- a/samples/AuthorizeIntentExamples/createOrder.ts +++ b/samples/AuthorizeIntentExamples/createOrder.ts @@ -1,4 +1,4 @@ -import { OrdersCreateRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient } from 'samples/Common/payPalClient.js'; /** @@ -134,9 +134,9 @@ function buildMinimumRequestBody() { */ export async function createOrderWithCompletePayload(debug = false) { try { - const request = new OrdersCreateRequest(); + const request = new orders.OrdersCreateRequest(); request.headers['prefer'] = 'return=representation'; - request.requestBody(buildCompleteRequestBody()); + request.requestBody(buildCompleteRequestBody() as any); const response = await createClient().execute(request); if (debug) { console.log('Creating Order with Complete Payload:'); @@ -172,9 +172,9 @@ export async function createOrderWithCompletePayload(debug = false) { */ export async function createOrderWithPartialPayload(debug = false) { try { - const request = new OrdersCreateRequest(); + const request = new orders.OrdersCreateRequest(); request.prefer('return=representation'); - request.requestBody(buildMinimumRequestBody()); + request.requestBody(buildMinimumRequestBody() as any); const response = await createClient().execute(request); if (debug) { console.log('Creating Order with Partial Payload:'); diff --git a/samples/CaptureIntentExamples/captureOrder.ts b/samples/CaptureIntentExamples/captureOrder.ts index 7c81171..c58c22c 100644 --- a/samples/CaptureIntentExamples/captureOrder.ts +++ b/samples/CaptureIntentExamples/captureOrder.ts @@ -1,4 +1,4 @@ -import { OrdersCaptureRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient } from 'tests/test-utils.js'; /** @@ -11,8 +11,8 @@ import { createClient } from 'tests/test-utils.js'; */ export async function captureOrder(orderId, debug = false) { try { - const request = new OrdersCaptureRequest(orderId); - request.requestBody({}); + const request = new orders.OrdersCaptureRequest(orderId); + request.requestBody({} as any); const response = await createClient().execute(request); if (debug) { console.log('Status Code: ' + response.statusCode); diff --git a/samples/CaptureIntentExamples/createOrder.ts b/samples/CaptureIntentExamples/createOrder.ts index 9b739df..7268b55 100644 --- a/samples/CaptureIntentExamples/createOrder.ts +++ b/samples/CaptureIntentExamples/createOrder.ts @@ -1,4 +1,4 @@ -import { OrdersCreateRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient } from 'tests/test-utils.js'; /** @@ -108,9 +108,9 @@ function buildRequestBody() { */ export async function createOrder(debug = false) { try { - const request = new OrdersCreateRequest(); + const request = new orders.OrdersCreateRequest(); request.headers['prefer'] = 'return=representation'; - request.requestBody(buildRequestBody()); + request.requestBody(buildRequestBody() as any); const response = await createClient().execute(request); if (debug) { console.log('Status Code: ' + response.statusCode); diff --git a/samples/Common/errorSample.ts b/samples/Common/errorSample.ts index 660d497..209b474 100644 --- a/samples/Common/errorSample.ts +++ b/samples/Common/errorSample.ts @@ -1,4 +1,4 @@ -import { OrdersCreateRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient, prettyPrint } from './payPalClient.js'; /** @@ -6,9 +6,9 @@ import { createClient, prettyPrint } from './payPalClient.js'; */ async function createError1() { try { - const request = new OrdersCreateRequest(); + const request = new orders.OrdersCreateRequest(); request.prefer('return=representation'); - request.requestBody({}); + request.requestBody({} as any); console.log(`Request Body:\n${JSON.stringify(request.body, null, 4)}`); console.log('Response:'); await createClient().execute(request); @@ -23,12 +23,12 @@ async function createError1() { */ async function createError2() { try { - const request = new OrdersCreateRequest(); + const request = new orders.OrdersCreateRequest(); request.prefer('return=representation'); request.requestBody({ intent: 'INVALID', purchase_units: [{ amount: { currency_code: 'USD', value: '100.00' } }], - }); + } as any); console.log(`Request Body:\n${JSON.stringify(request.body, null, 4)}`); console.log('Response:'); await createClient().execute(request); diff --git a/samples/Common/getOrder.ts b/samples/Common/getOrder.ts index 862ea43..8e26031 100644 --- a/samples/Common/getOrder.ts +++ b/samples/Common/getOrder.ts @@ -1,4 +1,4 @@ -import { OrdersGetRequest } from '@hyperse-io/paypal-node-sdk'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createClient } from './payPalClient.js'; /** @@ -9,7 +9,7 @@ import { createClient } from './payPalClient.js'; * @returns */ export async function getOrder(orderId) { - const request = new OrdersGetRequest(orderId); + const request = new orders.OrdersGetRequest(orderId); const response = await createClient().execute(request); console.log('Status Code: ' + response.statusCode); console.log('Status: ' + response.result.status); diff --git a/samples/Common/patchOrder.ts b/samples/Common/patchOrder.ts index 31f09dd..eb3e876 100644 --- a/samples/Common/patchOrder.ts +++ b/samples/Common/patchOrder.ts @@ -1,4 +1,4 @@ -import { OrdersPatchRequest } from '../../src/orders/ordersPatchRequest.js'; +import { orders } from '@hyperse-io/paypal-node-sdk'; import { createOrder } from '../CaptureIntentExamples/createOrder.js'; import { getOrder } from './getOrder.js'; import { createClient } from './payPalClient.js'; @@ -32,8 +32,8 @@ function buildRequestBody() { } async function patchOrder(orderId) { - const request = new OrdersPatchRequest(orderId); - request.requestBody(buildRequestBody()); + const request = new orders.OrdersPatchRequest(orderId); + request.requestBody(buildRequestBody() as any); const response = await createClient().execute(request); console.log('PATCH Status Code: ' + response.statusCode); // To toggle print the whole body comment/uncomment the below line diff --git a/samples/Common/payPalClient.ts b/samples/Common/payPalClient.ts index a103c2f..764bee6 100755 --- a/samples/Common/payPalClient.ts +++ b/samples/Common/payPalClient.ts @@ -1,8 +1,4 @@ -import { - LiveEnvironment, - PayPalHttpClient, - SandboxEnvironment, -} from '@hyperse-io/paypal-node-sdk'; +import { core } from '@hyperse-io/paypal-node-sdk'; /** * Returns PayPal HTTP client instance with environment which has access @@ -10,7 +6,7 @@ import { * credentials have the access to do so. */ export function createClient() { - return new PayPalHttpClient(environment()); + return new core.PayPalHttpClient(environment()); } /** @@ -23,10 +19,10 @@ function environment() { const clientSecret = process.env.PAYPAL_CLIENT_SECRET || '<>'; if (process.env.NODE_ENV === 'production') { - return new LiveEnvironment(clientId, clientSecret); + return new core.LiveEnvironment(clientId, clientSecret); } - return new SandboxEnvironment(clientId, clientSecret); + return new core.SandboxEnvironment(clientId, clientSecret); } export async function prettyPrint(jsonData, pre = '') { diff --git a/samples/Common/refundOrder.ts b/samples/Common/refundOrder.ts index 6f445f2..b16aad6 100644 --- a/samples/Common/refundOrder.ts +++ b/samples/Common/refundOrder.ts @@ -1,4 +1,4 @@ -import { CapturesRefundRequest } from '@hyperse-io/paypal-node-sdk'; +import { payments } from '@hyperse-io/paypal-node-sdk'; import { createClient } from './payPalClient.js'; /** * This method can be used to refund the capture. This function should be called @@ -10,13 +10,13 @@ import { createClient } from './payPalClient.js'; */ export async function refundOrder(captureId, debug = false) { try { - const request = new CapturesRefundRequest(captureId); + const request = new payments.CapturesRefundRequest(captureId); request.requestBody({ amount: { value: '20.00', currency_code: 'USD', }, - }); + } as any); const response = await createClient().execute(request); if (debug) { console.log('Status Code: ' + response.statusCode); diff --git a/src/core/AccessToken.ts b/src/core/AccessToken.ts index 69d9b18..332d601 100644 --- a/src/core/AccessToken.ts +++ b/src/core/AccessToken.ts @@ -1,35 +1,44 @@ /** - * A small amount of time to loosen the token expiration algorithm - * @constant EXPIRATION_THRESHOLD - * @type {number} + * Documentation + * + * @see {@link https://github.com/paypal/Checkout-NodeJS-SDK/blob/develop/lib/core/access_token.js} */ -const EXPIRATION_THRESHOLD = 500; -/** - * The access token object as it was granted by the token endpoint - */ -type AccessTokenOptions = { +export interface AccessTokenOptions { /** * The access token */ access_token: string; + /** * The token type */ - token_type: string; + expires_in: number; + /** * The duration of the token in milliseconds */ - expires_in: number; + token_type: string; + /** * The refresh token if any to refresh the current token */ - refresh_token?: string; -}; + refresh_token: string; +} + +/** + * A small amount of time to loosen the token expiration algorithm + */ +const EXPIRATION_THRESHOLD = 500; /** * An OAuth2 access token + * + * Documentation + * + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/AccessToken.ts} */ + export class AccessToken { private _accessToken: string; private _tokenType: string; @@ -45,7 +54,7 @@ export class AccessToken { /** * Get the expiration status of the token - * @return {boolean} - True if the token is expired otherwise false + * @return - True if the token is expired otherwise false */ isExpired() { return ( @@ -55,7 +64,7 @@ export class AccessToken { /** * Get the value of an Authorization header with the current access token - * @return {string} - The Authorization header value + * @return The Authorization header value */ authorizationString() { return `${this._tokenType} ${this._accessToken}`; diff --git a/src/core/AccessTokenRequest.ts b/src/core/AccessTokenRequest.ts index d595ef2..929651a 100644 --- a/src/core/AccessTokenRequest.ts +++ b/src/core/AccessTokenRequest.ts @@ -1,15 +1,25 @@ import { HttpRequestBase } from './HttpRequestBase.js'; import { type PayPalEnvironment } from './PayPalEnvironment.js'; -type AccessTokenRequestBody = { +export type AccessTokenRequestBody = { grant_type: string; refresh_token: string; }; +export type AccessTokenRequestHeaders = { + 'Content-Type': string; + Authorization: string; +}; + /** * An OAuth2 client credentials grant access token request + * Documentation + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/AccessTokenRequest.ts} */ -export class AccessTokenRequest extends HttpRequestBase { +export class AccessTokenRequest extends HttpRequestBase< + AccessTokenRequestHeaders, + AccessTokenRequestBody +> { /** * @param environment The environment for this request (sandbox or live) * @param refreshToken - An optional refresh token to use refreshing instead of granting diff --git a/src/core/HttpRequestBase.ts b/src/core/HttpRequestBase.ts index f59b458..f60c021 100644 --- a/src/core/HttpRequestBase.ts +++ b/src/core/HttpRequestBase.ts @@ -1,12 +1,30 @@ -import { type HttpHeaders, type HttpRequest } from '@paypal/paypalhttp'; +export interface BaseHeaders { + /** + * Will automatically be set to `Authorization` header value while http client + */ + Authorization?: string; +} + +export interface BaseRequest { + readonly path: string; + readonly verb: + | 'CONNECT' + | 'DELETE' + | 'GET' + | 'HEAD' + | 'OPTIONS' + | 'PATCH' + | 'POST' + | 'PUT'; + readonly body: B; + readonly headers: H; +} -export class HttpRequestBase - implements HttpRequest +export class HttpRequestBase + implements BaseRequest { - public body: T; - public headers: HttpHeaders; - public path: string; - public verb: + path: string; + verb: | 'CONNECT' | 'DELETE' | 'GET' @@ -15,8 +33,10 @@ export class HttpRequestBase | 'PATCH' | 'POST' | 'PUT'; + body: B; + headers: H; constructor() { - this.body = null as unknown as T; + this.body = null as any; } } diff --git a/src/core/PayPalEnvironment.ts b/src/core/PayPalEnvironment.ts index 66ccc90..94bc63f 100755 --- a/src/core/PayPalEnvironment.ts +++ b/src/core/PayPalEnvironment.ts @@ -7,6 +7,9 @@ const LIVE_WEB_URL = 'https://www.paypal.com'; /** * Base class for PayPal Environments + * Documentation + * + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/PayPalEnvironment.ts} */ export class PayPalEnvironment extends paypalhttp.Environment { public clientId: string; diff --git a/src/core/PayPalHttpClient.ts b/src/core/PayPalHttpClient.ts index e567ce3..40e0699 100755 --- a/src/core/PayPalHttpClient.ts +++ b/src/core/PayPalHttpClient.ts @@ -2,12 +2,17 @@ import paypalhttp, { type HttpRequest } from '@paypal/paypalhttp'; import packageJson from '../../package.json'; import { AccessToken } from './AccessToken.js'; import { AccessTokenRequest } from './AccessTokenRequest.js'; +import { type BaseRequest } from './HttpRequestBase.js'; import { type PayPalEnvironment } from './PayPalEnvironment.js'; import { TokenCache } from './TokenCache.js'; /** * PayPal Http client + * Documentation + * + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/PayPalHttpClient.ts} */ + export class PayPalHttpClient extends paypalhttp.HttpClient { private _cache: TokenCache; @@ -73,7 +78,9 @@ export class PayPalHttpClient extends paypalhttp.HttpClient { ); } - execute(request: HttpRequest) { + execute( + request: BaseRequest + ): Promise> { return super.execute(request).catch((err) => { if (err.statusCode === 401) { return this._retryRequest(request); diff --git a/src/core/RefreshTokenRequest.ts b/src/core/RefreshTokenRequest.ts index c624553..79811d0 100644 --- a/src/core/RefreshTokenRequest.ts +++ b/src/core/RefreshTokenRequest.ts @@ -1,14 +1,23 @@ +import { type AccessTokenRequestHeaders } from './AccessTokenRequest.js'; import { HttpRequestBase } from './HttpRequestBase.js'; import { type PayPalEnvironment } from './PayPalEnvironment.js'; -type RefreshTokenRequestBody = { +export type RefreshTokenRequestBody = { code: string; grant_type: string; }; /** * An OAuth2 refresh token request, granted from user consent. + * + * Documentation + * + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/RefreshTokenRequest.ts} */ -export class RefreshTokenRequest extends HttpRequestBase { + +export class RefreshTokenRequest extends HttpRequestBase< + AccessTokenRequestHeaders, + RefreshTokenRequestBody +> { /** * @param {PayPalEnvironment} environment - The environment for this request (sandbox or live) * @param {string} code - The authorization code provided at the end of the user consent OAuth flow. diff --git a/src/core/TokenCache.ts b/src/core/TokenCache.ts index 67c2124..9651622 100644 --- a/src/core/TokenCache.ts +++ b/src/core/TokenCache.ts @@ -7,6 +7,9 @@ const _cacheMap: Record = {}; /** * Stores token, token status and a request queue for every client + * Documentation + * + * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/TokenCache.ts} */ export class TokenCache { private _token: AccessToken | null; diff --git a/src/customers/customersPartnerMerchantIntegrationGetRequest.ts b/src/customers/customersPartnerMerchantIntegrationGetRequest.ts index e78b84c..81316a0 100644 --- a/src/customers/customersPartnerMerchantIntegrationGetRequest.ts +++ b/src/customers/customersPartnerMerchantIntegrationGetRequest.ts @@ -1,10 +1,11 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BaseCustomerHeaders } from './types.js'; /** Authorizes payment for an order. The response shows authorization details. **/ -export class CustomersPartnerMerchantIntegrationGetRequest extends HttpRequestBase { +export class CustomersPartnerMerchantIntegrationGetRequest extends HttpRequestBase { constructor(partnerMerchantId: string, sellerMerchantId: string) { super(); this.path = diff --git a/src/customers/customersPartnerReferralsGetRequest.ts b/src/customers/customersPartnerReferralsGetRequest.ts index 2d2a47f..08d448b 100644 --- a/src/customers/customersPartnerReferralsGetRequest.ts +++ b/src/customers/customersPartnerReferralsGetRequest.ts @@ -1,10 +1,11 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BaseCustomerHeaders } from './types.js'; /** Authorizes payment for an order. The response shows authorization details. **/ -export class CustomersPartnerReferralsGetRequest extends HttpRequestBase { +export class CustomersPartnerReferralsGetRequest extends HttpRequestBase { constructor(partnerReferralId: string) { super(); this.path = '/v2/customer/partner-referrals/{partner_referral_id}?'; diff --git a/src/customers/customersPartnerReferralsRequest.ts b/src/customers/customersPartnerReferralsRequest.ts index 2ec3051..3653fb4 100644 --- a/src/customers/customersPartnerReferralsRequest.ts +++ b/src/customers/customersPartnerReferralsRequest.ts @@ -1,4 +1,5 @@ import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BaseCustomerHeaders } from './types.js'; type CustomersPartnerReferralsRequestBody = { // @@ -7,7 +8,10 @@ type CustomersPartnerReferralsRequestBody = { /** Authorizes payment for an order. The response shows authorization details. **/ -export class CustomersPartnerReferralsRequest extends HttpRequestBase { +export class CustomersPartnerReferralsRequest extends HttpRequestBase< + BaseCustomerHeaders, + CustomersPartnerReferralsRequestBody +> { constructor() { super(); this.path = '/v2/customer/partner-referrals?'; diff --git a/src/customers/types.ts b/src/customers/types.ts new file mode 100644 index 0000000..c7c6fd7 --- /dev/null +++ b/src/customers/types.ts @@ -0,0 +1,5 @@ +import { type BaseHeaders } from '../core/HttpRequestBase.js'; + +export interface BaseCustomerHeaders extends BaseHeaders { + 'Content-Type': 'application/json'; +} diff --git a/src/orders/ordersAuthorizeRequest.ts b/src/orders/ordersAuthorizeRequest.ts index ca6cc21..836bd09 100755 --- a/src/orders/ordersAuthorizeRequest.ts +++ b/src/orders/ordersAuthorizeRequest.ts @@ -1,14 +1,25 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type PaymentSource, type BaseOrderHeaders } from './types.js'; -type OrdersAuthorizeRequestBody = { - // +export type OrdersAuthorizeRequestBody = { + payment_source: PaymentSource; }; +export interface OrdersAuthorizeRequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; +} + /** * Authorizes payment for an order. The response shows authorization details. + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_authorize} */ -export class OrdersAuthorizeRequest extends HttpRequestBase { +export class OrdersAuthorizeRequest extends HttpRequestBase< + OrdersAuthorizeRequestHeaders, + OrdersAuthorizeRequestBody +> { constructor(orderId: string) { super(); this.path = '/v2/checkout/orders/{order_id}/authorize?'; diff --git a/src/orders/ordersCaptureRequest.ts b/src/orders/ordersCaptureRequest.ts index eca23de..2184229 100755 --- a/src/orders/ordersCaptureRequest.ts +++ b/src/orders/ordersCaptureRequest.ts @@ -1,16 +1,27 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type PaymentSource, type BaseOrderHeaders } from './types.js'; /** * Captures a payment for an order payload */ -type OrdersCaptureRequestBody = { - // +export type OrdersCaptureRequestBody = { + payment_source: PaymentSource; }; +export interface OrdersCaptureRequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; +} /** * Captures a payment for an order. + * + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_capture} */ -export class OrdersCaptureRequest extends HttpRequestBase { +export class OrdersCaptureRequest extends HttpRequestBase< + OrdersCaptureRequestHeaders, + OrdersCaptureRequestBody +> { constructor(orderId: string) { super(); this.path = '/v2/checkout/orders/{order_id}/capture?'; diff --git a/src/orders/ordersCreateRequest.ts b/src/orders/ordersCreateRequest.ts index 7726729..20089fe 100755 --- a/src/orders/ordersCreateRequest.ts +++ b/src/orders/ordersCreateRequest.ts @@ -1,13 +1,31 @@ import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { + type CheckoutPaymentIntent, + type BaseOrderHeaders, + type Payer, + type PurchaseUnitRequest, + type OrderApplicationContext, +} from './types.js'; -type OrdersCreateRequestBody = { - // +export type OrdersCreateRequestBody = { + intent: CheckoutPaymentIntent; + payer?: Payer; + purchase_units: PurchaseUnitRequest[]; + application_context?: OrderApplicationContext; }; +export interface OrdersCreateRequestHeaders extends BaseOrderHeaders { + 'PayPal-Partner-Attribution-Id'?: string; + Prefer?: string; +} + /** * Creates an order. */ -export class OrdersCreateRequest extends HttpRequestBase { +export class OrdersCreateRequest extends HttpRequestBase< + OrdersCreateRequestHeaders, + OrdersCreateRequestBody +> { constructor() { super(); this.path = '/v2/checkout/orders?'; diff --git a/src/orders/ordersGetRequest.ts b/src/orders/ordersGetRequest.ts index 9d6bb6f..ce8effd 100755 --- a/src/orders/ordersGetRequest.ts +++ b/src/orders/ordersGetRequest.ts @@ -1,10 +1,12 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BaseOrderHeaders } from './types.js'; /** * Shows details for an order, by ID. + * @see {@link https://developer.paypal.com/api/orders/v2/#orders_get} */ -export class OrdersGetRequest extends HttpRequestBase { +export class OrdersGetRequest extends HttpRequestBase { constructor(orderId: string) { super(); this.path = '/v2/checkout/orders/{order_id}?'; diff --git a/src/orders/ordersPatchRequest.ts b/src/orders/ordersPatchRequest.ts index 50e1a81..4f16948 100755 --- a/src/orders/ordersPatchRequest.ts +++ b/src/orders/ordersPatchRequest.ts @@ -1,31 +1,17 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type Patch, type BaseOrderHeaders } from './types.js'; + +type OrderPatchRequestBody = Patch[]; -type OrderPatchRequestBody = { - // TODO: -}; /** * Updates an order. You can update an order with `CREATED` or `APPROVED` status. * You cannot update an order with `COMPLETED` status. The following attributes and objects are patchable: - * @example - * ```html - *
    - *
  • intent. - * Supported operation is replace. - *
  • - * < - * li>purchase_units. Support - * ed operations are add and replace. - *
  • purchase_units[].custom_id. Supported operations are add and replace and remove.
  • - *
  • purchase_units[].description. Supported operations are add and replace and remove.
  • - *
  • purchase_units[].payee.email. Supported operations are add and replace.
  • - *
  • purchase_units[].shipping_address. Supported operations are add and replace and remove.
  • - *
  • purchase_units[].soft_descriptor. Supported operations are add and replace and remove.
  • - *
  • purchase_units[].amount. Supported operation is replace.
  • - * /ul> - * ``` */ -export class OrdersPatchRequest extends HttpRequestBase { +export class OrdersPatchRequest extends HttpRequestBase< + BaseOrderHeaders, + OrderPatchRequestBody +> { constructor(orderId: string) { super(); this.path = '/v2/checkout/orders/{order_id}?'; diff --git a/src/orders/ordersValidateRequest.ts b/src/orders/ordersValidateRequest.ts index 43c6266..0a4f13d 100755 --- a/src/orders/ordersValidateRequest.ts +++ b/src/orders/ordersValidateRequest.ts @@ -1,14 +1,20 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BaseOrderHeaders } from './types.js'; -type OrdersValidateRequestBody = { - // -}; +type OrdersValidateRequestBody = Record; + +export interface OrdersValidateRequestHeaders extends BaseOrderHeaders { + 'PayPal-Client-Metadata-Id'?: string; +} /** * Validates a payment method and checks it for contingencies. */ -export class OrdersValidateRequest extends HttpRequestBase { +export class OrdersValidateRequest extends HttpRequestBase< + OrdersValidateRequestHeaders, + OrdersValidateRequestBody +> { constructor(orderId: string) { super(); this.path = '/v2/checkout/orders/{order_id}/validate-payment-method?'; diff --git a/src/orders/types.ts b/src/orders/types.ts new file mode 100644 index 0000000..ba29954 --- /dev/null +++ b/src/orders/types.ts @@ -0,0 +1,241 @@ +import { type BaseHeaders } from '../core/HttpRequestBase.js'; + +export interface BaseOrderHeaders extends BaseHeaders { + 'Content-Type': 'application/json'; +} + +export type TokenType = 'BILLING_AGREEMENT'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-token +export interface Token { + id: string; + type: TokenType; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_source +export interface PaymentSource { + token: Token; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-checkout_payment_intent +export type CheckoutPaymentIntent = 'CAPTURE' | 'AUTHORIZE'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payer_base +export interface PayerBase { + email_address: string; + payer_id: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-name +export interface Name { + alternate_full_name: string; + full_name: string; + given_name: string; + middle_name: string; + prefix: string; + suffix: string; + surname: string; +} + +export type PhoneType = 'FAX' | 'HOME' | 'MOBILE' | 'OTHER' | 'PAGER' | 'WORK'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-phone_with_type +export interface PhoneWithType { + phone_type?: PhoneType; + phone_number: { + national_number: string; + }; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payer +export interface Payer extends PayerBase { + address: AddressPortable; + birth_date: string; + name: Name; + phone: PhoneWithType; + tax_info: TaxInfo; +} + +export type TaxIdType = 'BR_CNPJ' | 'BR_CPF'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-tax_info +export interface TaxInfo { + tax_id_type: TaxIdType; + tax_id: string; +} +// https://developer.paypal.com/docs/api/payments/v2/#definition-address_details +export interface AddressDetails { + building_name: string; + delivery_service: string; + street_name: string; + street_number: string; + street_type: string; + sub_building: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-address_portable +export interface AddressPortable { + address_details?: AddressDetails; + address_line_1?: string; + address_line_2?: string; + address_line_3?: string; + admin_area_1?: string; + admin_area_2?: string; + admin_area_3?: string; + admin_area_4?: string; + country_code: string; + postal_code?: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-money +export interface Money { + currency_code: string; + value: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-amount_breakdown +export interface AmountBreakdown { + discount: Money; + handling: Money; + insurance: Money; + item_total: Money; + shipping_discount: Money; + shipping: Money; + tax_total: Money; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-amount_with_breakdown +export interface AmountWithBreakdown { + breakdown?: AmountBreakdown; + currency_code: string; + value: string; +} + +export type Category = 'DIGITAL_GOODS' | 'PHYSICAL_GOODS' | 'DONATION'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-item +export interface Item { + name: string; + unit_amount: Money; + tax?: Money; + quantity: string; + description?: string; + sku?: string; + category: Category; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payee +export interface Payee { + email_address?: string; + merchant_id?: string; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-disbursement_mode +export type DisbursementMode = 'DELAYED' | 'INSTANT'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payee_base +export type PayeeBase = Payee; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee +export interface PlatformFee { + amount: Money; + payee?: PayeeBase; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction +export interface PaymentInstruction { + disbursement_mode: DisbursementMode; + payee_pricing_tier_id: string; + platform_fees: PlatformFee[]; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-shipping_type +export type ShippingType = 'PICKUP' | 'PICKUP_IN_PERSON' | 'SHIPPING'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-shipping_detail +export interface ShippingDetail { + address: { + address_line_1?: string; + address_line_2?: string; + admin_area_1?: string; + admin_area_2?: string; + country_code: string; + postal_code?: string; + }; + name?: { + full_name?: string; + }; + type?: ShippingType; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request +export interface PurchaseUnitRequest { + amount: AmountWithBreakdown; + custom_id?: string; + description?: string; + invoice_id?: string; + items?: Item[]; + payee?: Payee; + payment_instruction?: PaymentInstruction; + reference_id?: string; + shipping?: ShippingDetail; + soft_descriptor?: string; +} + +export type LandingPage = 'LOGIN' | 'BILLING' | 'NO_PREFERENCE'; + +export type ShippingPreference = + | 'GET_FROM_FILE' + | 'NO_SHIPPING' + | 'SET_PROVIDED_ADDRESS'; + +export type UserAction = 'CONTINUE' | 'PAY_NOW'; + +export type PayeePreferred = 'IMMEDIATE_PAYMENT_REQUIRED' | 'UNRESTRICTED'; + +export type StandardEntryClassCode = 'CCD' | 'PPD' | 'TEL' | 'WEB'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_method +export interface PaymentMethod { + payee_preferred: PayeePreferred; + payer_selected: string; + standard_entry_class_code: StandardEntryClassCode; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-payment_initiator +export type PaymentInitiator = 'CUSTOMER' | 'MERCHANT'; + +export type PaymentType = 'ONE_TIME' | 'RECURRING' | 'UNSCHEDULED'; + +export type Usage = 'DERIVED' | 'FIRST' | 'SUBSEQUENT'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-stored_payment_source +export interface StoredPaymentSource { + payment_initiator: PaymentInitiator; + payment_type: PaymentType; + usage?: Usage; + previous_network_transaction_reference?: object; +} + +// https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context +export interface OrderApplicationContext { + brand_name?: string; + locale?: string; + landing_page?: LandingPage; + shipping_preference?: ShippingPreference; + user_action?: UserAction; + payment_method?: PaymentMethod; + return_url?: string; + cancel_url?: string; + stored_payment_source?: StoredPaymentSource; +} + +export type Operation = 'add' | 'copy' | 'move' | 'remove' | 'replace' | 'test'; + +// https://developer.paypal.com/docs/api/orders/v2/#definition-patch +export interface Patch { + from: string; + op: Operation; + path: string; + value: any; +} diff --git a/src/payments/authorizationsCaptureRequest.ts b/src/payments/authorizationsCaptureRequest.ts index a1be3c0..518be95 100755 --- a/src/payments/authorizationsCaptureRequest.ts +++ b/src/payments/authorizationsCaptureRequest.ts @@ -1,14 +1,30 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type Money } from '../orders/types.js'; +import { type PaymentInstruction, type BasePaymentHeaders } from './types.js'; type AuthorizationsCaptureRequestBody = { - // + amount: Money; + final_capture: boolean; + invoice_id: string; + note_to_payer: string; + payment_instruction?: PaymentInstruction; + soft_descriptor: string; }; -/** - Captures an authorized payment, by ID. - **/ -export class AuthorizationsCaptureRequest extends HttpRequestBase { +interface AuthorizationsCaptureRequestHeaders extends BasePaymentHeaders { + 'PayPal-Request-Id'?: string; + Prefer?: string; +} + +/** + * Captures an authorized payment, by ID. + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_capture} + */ +export class AuthorizationsCaptureRequest extends HttpRequestBase< + AuthorizationsCaptureRequestHeaders, + AuthorizationsCaptureRequestBody +> { constructor(authorizationId) { super(); this.path = '/v2/payments/authorizations/{authorization_id}/capture?'; diff --git a/src/payments/authorizationsGetRequest.ts b/src/payments/authorizationsGetRequest.ts index 98bc42b..5b462d8 100755 --- a/src/payments/authorizationsGetRequest.ts +++ b/src/payments/authorizationsGetRequest.ts @@ -1,11 +1,13 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BasePaymentHeaders } from './types.js'; /* * Shows details for an authorized payment, by ID. + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_get} */ -export class AuthorizationsGetRequest extends HttpRequestBase { - constructor(authorizationId) { +export class AuthorizationsGetRequest extends HttpRequestBase { + constructor(authorizationId: string) { super(); this.path = '/v2/payments/authorizations/{authorization_id}?'; this.path = this.path.replace( diff --git a/src/payments/authorizationsReauthorizeRequest.ts b/src/payments/authorizationsReauthorizeRequest.ts index a88303b..f48ad9f 100755 --- a/src/payments/authorizationsReauthorizeRequest.ts +++ b/src/payments/authorizationsReauthorizeRequest.ts @@ -1,16 +1,26 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type Money } from '../orders/types.js'; +import { type BasePaymentHeaders } from './types.js'; type AuthorizationsReauthorizeRequestBody = { - // + amount: Money; }; + +export interface AuthorizationsReauthorizeRequestHeaders + extends BasePaymentHeaders { + 'PayPal-Request-Id'?: string; + Prefer?: string; +} + /** - Reauthorizes an authorized PayPal account payment, by ID. - To ensure that funds are still available, reauthorize an authorized payment after its initial three-day honor period expires. -

    After the three-day honor period expires, you can reauthorize an authorized payment only once from days four to 29. If 30 days have passed since the date of the authorized payment, you must create an authorized payment instead. -

    A reauthorized payment itself has a new three-day honor period. You can reauthorize an authorized payment once for up to 115% of the original authorized amount and not to exceed an increase of $75 USD.

    Supports the amount request parameter only. - **/ -export class AuthorizationsReauthorizeRequest extends HttpRequestBase { + * Authorizations Reauthorize + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_reauthorize} + */ +export class AuthorizationsReauthorizeRequest extends HttpRequestBase< + AuthorizationsReauthorizeRequestHeaders, + AuthorizationsReauthorizeRequestBody +> { constructor(authorizationId: string) { super(); this.path = '/v2/payments/authorizations/{authorization_id}/reauthorize?'; diff --git a/src/payments/authorizationsVoidRequest.ts b/src/payments/authorizationsVoidRequest.ts index f18a289..528a97d 100755 --- a/src/payments/authorizationsVoidRequest.ts +++ b/src/payments/authorizationsVoidRequest.ts @@ -1,14 +1,16 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BasePaymentHeaders } from './types.js'; -type AuthorizationsVoidRequestBody = { - // -}; - +interface AuthorizationsVoidRequestHeaders extends BasePaymentHeaders { + 'PayPal-Auth-Assertion'?: string; + Prefer?: string; +} /** * Voids, or cancels, an authorized payment, by ID. You cannot void an authorized payment that has been fully captured. + * @see {@link https://developer.paypal.com/api/payments/v2/#authorizations_void} */ -export class AuthorizationsVoidRequest extends HttpRequestBase { +export class AuthorizationsVoidRequest extends HttpRequestBase { constructor(authorizationId: string) { super(); this.path = '/v2/payments/authorizations/{authorization_id}/void?'; diff --git a/src/payments/capturesGetRequest.ts b/src/payments/capturesGetRequest.ts index 1bebf19..1178af7 100755 --- a/src/payments/capturesGetRequest.ts +++ b/src/payments/capturesGetRequest.ts @@ -1,10 +1,13 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BasePaymentHeaders } from './types.js'; /** + * Captures Get * Shows details for a captured payment, by ID. + * @see {@link https://developer.paypal.com/api/payments/v2/#captures_get} */ -export class CapturesGetRequest extends HttpRequestBase { +export class CapturesGetRequest extends HttpRequestBase { constructor(captureId: string) { super(); this.path = '/v2/payments/captures/{capture_id}?'; diff --git a/src/payments/capturesRefundRequest.ts b/src/payments/capturesRefundRequest.ts index 5e6e666..c014b24 100755 --- a/src/payments/capturesRefundRequest.ts +++ b/src/payments/capturesRefundRequest.ts @@ -1,15 +1,28 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type Money } from '../orders/types.js'; +import { type BasePaymentHeaders } from './types.js'; type CapturesRefundRequestBody = { - // + amount: Money; + invoice_id: string; + note_to_payer: string; }; +interface CapturesRefundRequestHeaders extends BasePaymentHeaders { + 'PayPal-Auth-Assertion'?: string; + 'PayPal-Request-Id'?: string; + Prefer?: string; +} /** * Refunds a captured payment, by ID. For a full refund, include an empty payload in the JSON request body. * For a partial refund, include an amount object in the JSON request body. + * @see {@link https://developer.paypal.com/api/payments/v2/#captures_refund} */ -export class CapturesRefundRequest extends HttpRequestBase { +export class CapturesRefundRequest extends HttpRequestBase< + CapturesRefundRequestHeaders, + CapturesRefundRequestBody +> { constructor(captureId) { super(); this.path = '/v2/payments/captures/{capture_id}/refund?'; diff --git a/src/payments/index.ts b/src/payments/index.ts index e8be280..6f1b9e6 100755 --- a/src/payments/index.ts +++ b/src/payments/index.ts @@ -4,7 +4,6 @@ import { AuthorizationsReauthorizeRequest } from './authorizationsReauthorizeReq import { AuthorizationsVoidRequest } from './authorizationsVoidRequest.js'; import { CapturesGetRequest } from './capturesGetRequest.js'; import { CapturesRefundRequest } from './capturesRefundRequest.js'; -import { ReferencedPayoutsItemsRequest } from './referencedPayoutsItems.js'; import { RefundsGetRequest } from './refundsGetRequest.js'; export const payments = { @@ -14,6 +13,5 @@ export const payments = { AuthorizationsVoidRequest, CapturesGetRequest, CapturesRefundRequest, - ReferencedPayoutsItemsRequest, RefundsGetRequest, }; diff --git a/src/payments/referencedPayoutsItems.ts b/src/payments/referencedPayoutsItems.ts deleted file mode 100644 index 76b4eea..0000000 --- a/src/payments/referencedPayoutsItems.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Shows details for a refund, by ID. - */ -import { HttpRequestBase } from '../core/HttpRequestBase.js'; - -type ReferencedPayoutsItemsRequestBody = { - // -}; - -export class ReferencedPayoutsItemsRequest extends HttpRequestBase { - constructor() { - super(); - this.path = '/v1/payments/referenced-payouts-items?'; - this.verb = 'POST'; - this.headers = { - 'Content-Type': 'application/json', - }; - } - - payPalPartnerAttributionId(payPalPartnerAttributionId: string) { - this.headers['PayPal-Partner-Attribution-Id'] = payPalPartnerAttributionId; - return this; - } - - requestBody(order: ReferencedPayoutsItemsRequestBody) { - this.body = order; - return this; - } -} diff --git a/src/payments/refundsGetRequest.ts b/src/payments/refundsGetRequest.ts index 9c5b4d7..791a65a 100755 --- a/src/payments/refundsGetRequest.ts +++ b/src/payments/refundsGetRequest.ts @@ -1,10 +1,12 @@ import querystring from 'querystring'; import { HttpRequestBase } from '../core/HttpRequestBase.js'; +import { type BasePaymentHeaders } from './types.js'; /** * Shows details for a refund, by ID. + * @see {@link https://developer.paypal.com/api/payments/v2/#refunds_get} */ -export class RefundsGetRequest extends HttpRequestBase { +export class RefundsGetRequest extends HttpRequestBase { constructor(refundId: string) { super(); this.path = '/v2/payments/refunds/{refund_id}?'; diff --git a/src/payments/types.ts b/src/payments/types.ts new file mode 100644 index 0000000..9ae47fc --- /dev/null +++ b/src/payments/types.ts @@ -0,0 +1,22 @@ +import { type BaseHeaders } from '../core/HttpRequestBase.js'; +import { type Money, type PayeeBase } from '../orders/types.js'; + +export interface BasePaymentHeaders extends BaseHeaders { + 'Content-Type': 'application/json'; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-disbursement_mode +export type DisbursementMode = 'DELAYED' | 'INSTANT'; + +// https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee +export interface PlatformFee { + amount: Money; + payee?: PayeeBase; +} + +// https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction +export interface PaymentInstruction { + disbursement_mode: DisbursementMode; + payee_pricing_tier_id: string; + platform_fees: PlatformFee[]; +} diff --git a/tests/orders/order-utils.ts b/tests/orders/order-utils.ts index 4a9f293..0818452 100644 --- a/tests/orders/order-utils.ts +++ b/tests/orders/order-utils.ts @@ -21,6 +21,6 @@ function buildRequestBody() { export function createOrder() { const request = new OrdersCreateRequest(); request.prefer('return=representation'); - request.requestBody(buildRequestBody()); + request.requestBody(buildRequestBody() as any); return client.execute(request); } diff --git a/tests/orders/ordersPatch.spec.ts b/tests/orders/ordersPatch.spec.ts index ed5e787..f49e8f7 100755 --- a/tests/orders/ordersPatch.spec.ts +++ b/tests/orders/ordersPatch.spec.ts @@ -27,7 +27,7 @@ describe('OrdersPatchRequest', () => { const createOrderResponse = await createOrder(); expect(createOrderResponse.statusCode).toBe(201); const patchRequest = new OrdersPatchRequest(createOrderResponse.result.id); - patchRequest.requestBody(buildRequestBody()); + patchRequest.requestBody(buildRequestBody() as any); const patchResponse = await client.execute(patchRequest); expect(patchResponse.statusCode).toBe(204); diff --git a/tsconfig.json b/tsconfig.json index 2935db7..5a566f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ }, "types": ["@types/node", "vitest/globals"] }, - "exclude": ["**/node_modules", "**/.*/", "dist", "build"] + "exclude": ["**/node_modules", "**/.*/", "dist", "build", "docs/typings"] } diff --git a/yarn.lock b/yarn.lock index 5907f99..d8540e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -787,6 +787,7 @@ __metadata: "@paypal/paypalhttp": "npm:^1.0.1" "@swc/core": "npm:1.5.7" "@types/node": "npm:20.12.12" + "@types/paypal__checkout-server-sdk": "npm:^1.0.8" "@types/paypal__paypalhttp": "npm:^1.0.3" "@types/prettier": "npm:3.0.0" "@types/shell-quote": "npm:1.7.5" @@ -1335,7 +1336,16 @@ __metadata: languageName: node linkType: hard -"@types/paypal__paypalhttp@npm:^1.0.3": +"@types/paypal__checkout-server-sdk@npm:^1.0.8": + version: 1.0.8 + resolution: "@types/paypal__checkout-server-sdk@npm:1.0.8" + dependencies: + "@types/paypal__paypalhttp": "npm:*" + checksum: 10/41fcc27397576cd450a19ce548c50cb6cfccbf1a085c4dd852438ed60b3c66675f03662bb9232f42031bf36d9762607d9e7b2a84507d9a0ac1a884668f544547 + languageName: node + linkType: hard + +"@types/paypal__paypalhttp@npm:*, @types/paypal__paypalhttp@npm:^1.0.3": version: 1.0.3 resolution: "@types/paypal__paypalhttp@npm:1.0.3" dependencies: