From 07638243a6e7362e56edd6c0ea4d9ecddeca1042 Mon Sep 17 00:00:00 2001 From: tianyingchun Date: Fri, 7 Jun 2024 18:25:25 +0800 Subject: [PATCH] feat: improved typings for OrdersCreateRequest --- .changeset/warm-tables-fry.md | 5 ++ package.json | 4 +- src/orders/ordersCreateRequest.ts | 14 +++- src/types/type-order.ts | 127 +++++++++++++++++++++++++++--- yarn.lock | 109 +++++++++++++------------ 5 files changed, 192 insertions(+), 67 deletions(-) create mode 100644 .changeset/warm-tables-fry.md diff --git a/.changeset/warm-tables-fry.md b/.changeset/warm-tables-fry.md new file mode 100644 index 0000000..6df0428 --- /dev/null +++ b/.changeset/warm-tables-fry.md @@ -0,0 +1,5 @@ +--- +"@hyperse/paypal-node-sdk": patch +--- + +improved typings for OrdersCreateRequest diff --git a/package.json b/package.json index 559413b..bebce4b 100644 --- a/package.json +++ b/package.json @@ -79,10 +79,10 @@ "devDependencies": { "@changesets/changelog-git": "0.2.0", "@changesets/changelog-github": "0.5.0", - "@changesets/cli": "2.27.1", + "@changesets/cli": "2.27.5", "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", - "@hyperse/eslint-config-hyperse": "^1.0.4", + "@hyperse/eslint-config-hyperse": "^1.0.7", "@swc/core": "1.5.25", "@types/node": "20.14.2", "commitizen": "4.3.0", diff --git a/src/orders/ordersCreateRequest.ts b/src/orders/ordersCreateRequest.ts index 5c3bfcb..8c02ac5 100755 --- a/src/orders/ordersCreateRequest.ts +++ b/src/orders/ordersCreateRequest.ts @@ -3,14 +3,24 @@ import { type BaseOrderHeaders, type CheckoutPaymentIntent, type OrderApplicationContext, - type Payer, + PaymentSourceRequest, type PurchaseUnitRequest, } from '../types/type-order.js'; export type OrdersCreateRequestBody = { intent: CheckoutPaymentIntent; - payer?: Payer; + /** + * The payment source definition. + */ + payment_source?: PaymentSourceRequest; + /** + * An array of purchase units. Each purchase unit establishes a contract between a payer and the payee. + * Each purchase unit represents either a full or partial order that the payer intends to purchase from the payee. + */ purchase_units: PurchaseUnitRequest[]; + /** + * Customizes the payer experience during the approval process for the payment with PayPal. + */ application_context?: OrderApplicationContext; }; diff --git a/src/types/type-order.ts b/src/types/type-order.ts index d0fa446..83bb47f 100644 --- a/src/types/type-order.ts +++ b/src/types/type-order.ts @@ -398,6 +398,110 @@ export interface PurchaseUnit { soft_descriptor: string; } +// https://developer.paypal.com/docs/api/orders/v2/#definition-customized_payment_source_2 +export interface PaymentSourceRequest { + /** + * The tokenized payment source to fund a payment. + */ + token?: { + /** + * The PayPal-generated ID for the token. + */ + id: string; + /** + * The tokenization method that generated the ID. + */ + type: string; + }; + + /** + * Indicates that PayPal Wallet is the payment source. + * Main use of this selection is to provide additional instructions associated with this choice like vaulting. + */ + paypal?: { + /** + * Additional attributes associated with the use of this wallet. + */ + attributes?: { + /** + * Attributes used to provide the instructions during vaulting of the PayPal Wallet. + */ + vault?: { + /** + * Defines how and when the payment source gets vaulted. + * 'ON_SUCCESS' + */ + store_in_vault?: string; + /** + * The usage type associated with the PayPal payment token. + */ + usage_type: string; + }; + /** + * The details about a customer in PayPal's system of record. + */ + customer?: { + /** + * The unique ID for a customer generated by PayPal. + */ + id?: string; + /** + * Email address of the buyer as provided to the merchant or on file with the merchant. Email Address is required if you are processing the transaction using PayPal Guest Processing which is offered to select partners and merchants. + * For all other use cases we do not expect partners/merchant to send email_address of their customer. + */ + email_address?: string; + /** + * Merchants and partners may already have a data-store where their customer information is persisted. + * Use merchant_customer_id to associate the PayPal-generated customer.id to your representation of a customer. + */ + merchant_customer_id?: string; + }; + }; + /** + * Customizes the payer experience during the approval process for payment with PayPal. + */ + experience_context?: { + /** + * The label that overrides the business name in the PayPal account on the PayPal site. The pattern is defined by an external party and supports Unicode + */ + brand_name?: string; + /** + * The BCP 47-formatted locale of pages that the PayPal payment experience shows. PayPal supports a five-character code. + * For example, da-DK, he-IL, id-ID, ja-JP, no-NO, pt-BR, ru-RU, sv-SE, th-TH, zh-CN, zh-HK, or zh-TW. + */ + locale?: string; + /** + * The type of landing page to show on the PayPal site for customer checkout. + * @default "NO_PREFERENCE" + */ + landing_page?: 'LOGIN' | 'GUEST_CHECKOUT' | 'NO_PREFERENCE'; + /** + * The location from which the shipping address is derived. + * @default "GET_FROM_FILE" + */ + shipping_preference?: ShippingPreference; + /** + * Configures a Continue or Pay Now checkout flow. + * @default `CONTINUE` + */ + user_action?: UserAction; + /** + * The merchant-preferred payment methods. + * @default 'UNRESTRICTED' + */ + payment_method_preference?: 'UNRESTRICTED' | 'IMMEDIATE_PAYMENT_REQUIRED'; + /** + * The URL where the customer will be redirected upon approving a payment. + */ + return_url?: string; + /** + * The URL where the customer will be redirected upon cancelling the payment approval. + */ + cancel_url?: string; + }; + }; +} + // https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request export interface PurchaseUnitRequest { amount: AmountWithBreakdown; @@ -463,21 +567,22 @@ export interface PaymentSourceResponse { card: CardResponse; } -// https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context +/** + * Customize the payer experience during the approval process for the payment with PayPal. + * @see {@link https://developer.paypal.com/docs/api/orders/v2/#definition-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; + /** + * Provides additional details to process a payment using a payment_source that has been stored or is intended to be stored (also referred to as stored_credential or card-on-file). + * Parameter compatibility: + * payment_type=ONE_TIME is compatible only with payment_initiator=CUSTOMER. + * usage=FIRST is compatible only with payment_initiator=CUSTOMER. + * previous_transaction_reference or previous_network_transaction_reference is compatible only with payment_initiator=MERCHANT. + * Only one of the parameters - previous_transaction_reference and previous_network_transaction_reference - can be present in the request. + */ stored_payment_source?: StoredPaymentSource; } -export type LandingPage = 'LOGIN' | 'BILLING' | 'NO_PREFERENCE'; - export type ShippingPreference = | 'GET_FROM_FILE' | 'NO_SHIPPING' diff --git a/yarn.lock b/yarn.lock index 2df0cde..212b2ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -57,14 +57,15 @@ __metadata: languageName: node linkType: hard -"@changesets/apply-release-plan@npm:^7.0.0": - version: 7.0.0 - resolution: "@changesets/apply-release-plan@npm:7.0.0" +"@changesets/apply-release-plan@npm:^7.0.3": + version: 7.0.3 + resolution: "@changesets/apply-release-plan@npm:7.0.3" dependencies: "@babel/runtime": "npm:^7.20.1" - "@changesets/config": "npm:^3.0.0" + "@changesets/config": "npm:^3.0.1" "@changesets/get-version-range-type": "npm:^0.4.0" "@changesets/git": "npm:^3.0.0" + "@changesets/should-skip-package": "npm:^0.1.0" "@changesets/types": "npm:^6.0.0" "@manypkg/get-packages": "npm:^1.1.3" detect-indent: "npm:^6.0.0" @@ -74,21 +75,22 @@ __metadata: prettier: "npm:^2.7.1" resolve-from: "npm:^5.0.0" semver: "npm:^7.5.3" - checksum: 10/bf02351e8da1d507a3c1aeb28fddc7812ab027d5127c25af5522130fd676bfad219dbee4a8ebbe9eff7c0654c5b2c5e2451c13d4e02ff45d67990f4f0ff87775 + checksum: 10/3e8c7d20371c97e55b25d51b1ade6827d6489b86690b7ba4d766bb95c7088ccf46213fedc21a56e31a89ba9b6da3c6cd1213c6f3c54e758ebe7b3b40c79bd7e8 languageName: node linkType: hard -"@changesets/assemble-release-plan@npm:^6.0.0": - version: 6.0.0 - resolution: "@changesets/assemble-release-plan@npm:6.0.0" +"@changesets/assemble-release-plan@npm:^6.0.2": + version: 6.0.2 + resolution: "@changesets/assemble-release-plan@npm:6.0.2" dependencies: "@babel/runtime": "npm:^7.20.1" "@changesets/errors": "npm:^0.2.0" - "@changesets/get-dependents-graph": "npm:^2.0.0" + "@changesets/get-dependents-graph": "npm:^2.1.0" + "@changesets/should-skip-package": "npm:^0.1.0" "@changesets/types": "npm:^6.0.0" "@manypkg/get-packages": "npm:^1.1.3" semver: "npm:^7.5.3" - checksum: 10/ffa8d4877f72209d433987bbc67ac3974c7a06ac700036785e0882bc5bc543b7a52d6643e66c155836dc2e4b08b06fe363d058608a9d57c2c37651d7225222ee + checksum: 10/19fe2cb45561ebf6ca389a342268c897a8f5dad4926781ebda90a94951c8237c036afebed94bfc46cc202b559051b472f09197f655722902668f97016277a543 languageName: node linkType: hard @@ -112,24 +114,25 @@ __metadata: languageName: node linkType: hard -"@changesets/cli@npm:2.27.1": - version: 2.27.1 - resolution: "@changesets/cli@npm:2.27.1" +"@changesets/cli@npm:2.27.5": + version: 2.27.5 + resolution: "@changesets/cli@npm:2.27.5" dependencies: "@babel/runtime": "npm:^7.20.1" - "@changesets/apply-release-plan": "npm:^7.0.0" - "@changesets/assemble-release-plan": "npm:^6.0.0" + "@changesets/apply-release-plan": "npm:^7.0.3" + "@changesets/assemble-release-plan": "npm:^6.0.2" "@changesets/changelog-git": "npm:^0.2.0" - "@changesets/config": "npm:^3.0.0" + "@changesets/config": "npm:^3.0.1" "@changesets/errors": "npm:^0.2.0" - "@changesets/get-dependents-graph": "npm:^2.0.0" - "@changesets/get-release-plan": "npm:^4.0.0" + "@changesets/get-dependents-graph": "npm:^2.1.0" + "@changesets/get-release-plan": "npm:^4.0.2" "@changesets/git": "npm:^3.0.0" "@changesets/logger": "npm:^0.1.0" "@changesets/pre": "npm:^2.0.0" "@changesets/read": "npm:^0.6.0" + "@changesets/should-skip-package": "npm:^0.1.0" "@changesets/types": "npm:^6.0.0" - "@changesets/write": "npm:^0.3.0" + "@changesets/write": "npm:^0.3.1" "@manypkg/get-packages": "npm:^1.1.3" "@types/semver": "npm:^7.5.0" ansi-colors: "npm:^4.1.3" @@ -150,22 +153,22 @@ __metadata: tty-table: "npm:^4.1.5" bin: changeset: bin.js - checksum: 10/b7729fae49af7e707d55751a702095f46e0b1143e28e0ca191651ec1ac61fe54dc2e3c11db8476293e71f538f24cc3eb968b1dbe77ce74d3776a90c3468c1c27 + checksum: 10/12b289ba614f34be01fc07bcb5ce7283fe81a0725bf12e3223a1ec97db06ec6db16882c22a9ea3f5f9172faefd019cdc29d02159b53312b61cb51d540555bc62 languageName: node linkType: hard -"@changesets/config@npm:^3.0.0": - version: 3.0.0 - resolution: "@changesets/config@npm:3.0.0" +"@changesets/config@npm:^3.0.1": + version: 3.0.1 + resolution: "@changesets/config@npm:3.0.1" dependencies: "@changesets/errors": "npm:^0.2.0" - "@changesets/get-dependents-graph": "npm:^2.0.0" + "@changesets/get-dependents-graph": "npm:^2.1.0" "@changesets/logger": "npm:^0.1.0" "@changesets/types": "npm:^6.0.0" "@manypkg/get-packages": "npm:^1.1.3" fs-extra: "npm:^7.0.1" micromatch: "npm:^4.0.2" - checksum: 10/cff983c9af7c8103414a7325d9a196f532f3e7230d65fe9c8261baef9b09eea2f6e205f83530b6c6ece6efcf4adda49f02a491416a934d3bf27563439057b255 + checksum: 10/908cdd32779aae48a4f859e65769c72c15f8e8b66146e79079e06be5d1af074609e51983b44bf53c69ef1fa9a3e33e28aea65516465f399d038ae9df8ef32c10 languageName: node linkType: hard @@ -178,16 +181,16 @@ __metadata: languageName: node linkType: hard -"@changesets/get-dependents-graph@npm:^2.0.0": - version: 2.0.0 - resolution: "@changesets/get-dependents-graph@npm:2.0.0" +"@changesets/get-dependents-graph@npm:^2.1.0": + version: 2.1.0 + resolution: "@changesets/get-dependents-graph@npm:2.1.0" dependencies: "@changesets/types": "npm:^6.0.0" "@manypkg/get-packages": "npm:^1.1.3" chalk: "npm:^2.1.0" fs-extra: "npm:^7.0.1" semver: "npm:^7.5.3" - checksum: 10/9b44f2418b5902c9f19bcb70d697c654224fe8f9f8b06ff031a418cd0961e590c1e7a422966fe68d01d4914fd6eea7b1920fc26161ed46ea59a2ef96886e12ca + checksum: 10/8f34a8948aa497617cd433217f94a5f647fd342bd7c8d3c41042ccb4e1bd5aa397018ee07b8bf03c3f88531ba6092384b41a748ccbd49658d40189f656a04505 languageName: node linkType: hard @@ -201,18 +204,18 @@ __metadata: languageName: node linkType: hard -"@changesets/get-release-plan@npm:^4.0.0": - version: 4.0.0 - resolution: "@changesets/get-release-plan@npm:4.0.0" +"@changesets/get-release-plan@npm:^4.0.2": + version: 4.0.2 + resolution: "@changesets/get-release-plan@npm:4.0.2" dependencies: "@babel/runtime": "npm:^7.20.1" - "@changesets/assemble-release-plan": "npm:^6.0.0" - "@changesets/config": "npm:^3.0.0" + "@changesets/assemble-release-plan": "npm:^6.0.2" + "@changesets/config": "npm:^3.0.1" "@changesets/pre": "npm:^2.0.0" "@changesets/read": "npm:^0.6.0" "@changesets/types": "npm:^6.0.0" "@manypkg/get-packages": "npm:^1.1.3" - checksum: 10/9c893012d7b16e08acf51a76290a38e3bceac6e5421d5482baadf09e04db30c9159738580bd0695d33d51d9a30d4a72bf186f48785ea653f956397457afa44a5 + checksum: 10/5f4d66cf1f68a60854c40b0f565edb48743e2c8be6ca653df906af58e534ec8358fd8f22145d3790aa745f158ceb116a256723efda906eb05f7977ee66e52075 languageName: node linkType: hard @@ -286,6 +289,17 @@ __metadata: languageName: node linkType: hard +"@changesets/should-skip-package@npm:^0.1.0": + version: 0.1.0 + resolution: "@changesets/should-skip-package@npm:0.1.0" + dependencies: + "@babel/runtime": "npm:^7.20.1" + "@changesets/types": "npm:^6.0.0" + "@manypkg/get-packages": "npm:^1.1.3" + checksum: 10/3c966feae085a41d4ce10a46a1b525f980cec59951f7cf23ea805866b370de5c75fdd45af326e1a5ef502fa4846f821d9df15550c2b606b96e99ed4b967f01c0 + languageName: node + linkType: hard + "@changesets/types@npm:^4.0.1": version: 4.1.0 resolution: "@changesets/types@npm:4.1.0" @@ -300,16 +314,16 @@ __metadata: languageName: node linkType: hard -"@changesets/write@npm:^0.3.0": - version: 0.3.0 - resolution: "@changesets/write@npm:0.3.0" +"@changesets/write@npm:^0.3.1": + version: 0.3.1 + resolution: "@changesets/write@npm:0.3.1" dependencies: "@babel/runtime": "npm:^7.20.1" "@changesets/types": "npm:^6.0.0" fs-extra: "npm:^7.0.1" human-id: "npm:^1.0.2" prettier: "npm:^2.7.1" - checksum: 10/37588eb3ef2af15b3ea09d46864c994780619d20b791ea5b654801a035a3a12540c7f953e6e4f36731678615edc6d1c32f8fe174d599d3e6ce2d68263865788b + checksum: 10/13b9284e8cb9c55456b62fe4b8e27ab615e46b0214e1a62194afd4ecb33f5e6617478e01b031209d16348e01c7bce5a37cb18afe688c81d98f3657d7c40cc2c9 languageName: node linkType: hard @@ -740,7 +754,7 @@ __metadata: languageName: node linkType: hard -"@hyperse/eslint-config-hyperse@npm:^1.0.4": +"@hyperse/eslint-config-hyperse@npm:^1.0.7": version: 1.0.7 resolution: "@hyperse/eslint-config-hyperse@npm:1.0.7" dependencies: @@ -776,10 +790,10 @@ __metadata: dependencies: "@changesets/changelog-git": "npm:0.2.0" "@changesets/changelog-github": "npm:0.5.0" - "@changesets/cli": "npm:2.27.1" + "@changesets/cli": "npm:2.27.5" "@commitlint/cli": "npm:19.3.0" "@commitlint/config-conventional": "npm:19.2.2" - "@hyperse/eslint-config-hyperse": "npm:^1.0.4" + "@hyperse/eslint-config-hyperse": "npm:^1.0.7" "@paypal/paypalhttp": "npm:^1.0.1" "@swc/core": "npm:1.5.25" "@types/node": "npm:20.14.2" @@ -1372,16 +1386,7 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^20.0.0": - version: 20.12.12 - resolution: "@types/node@npm:20.12.12" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10/e3945da0a3017bdc1f88f15bdfb823f526b2a717bd58d4640082d6eb0bd2794b5c99bfb914b9e9324ec116dce36066990353ed1c777e8a7b0641f772575793c4 - languageName: node - linkType: hard - -"@types/node@npm:20.14.2": +"@types/node@npm:*, @types/node@npm:20.14.2, @types/node@npm:^20.0.0": version: 20.14.2 resolution: "@types/node@npm:20.14.2" dependencies: