-
Notifications
You must be signed in to change notification settings - Fork 143
Added card fields eligibility types #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16579f6
Update eligibility types to account for advanced_cards object in the …
48b27ba
Added type tests for card fields
bec655c
Created changeset
f7aef2d
Updated changeset from patch to minor
568ea3c
Merge branch 'main' into feature/4229-card-fields-eligibility-types
d902c96
Updated V6 Card Fields types to be cammelCase
f9310dc
Updated tests to check eligibility values
fd4d818
Merge branch 'main' into feature/4229-card-fields-eligibility-types
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@paypal/paypal-js": minor | ||
| --- | ||
|
|
||
| Added eligibility API typings for Card Fields and created card fields test file for its types |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { loadCoreSdkScript } from "../../../src/v6"; | ||
| import type { PayPalV6Namespace } from "../index"; | ||
|
|
||
| /** | ||
| * Type test for Card Fields integration | ||
| * | ||
| * @remarks | ||
| * This test verifies TypeScript compilation and type inference. | ||
| * The function is never executed — it's used for type-checking only. | ||
| */ | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| async function main() { | ||
| let paypal: PayPalV6Namespace | null; | ||
|
|
||
| try { | ||
| paypal = await loadCoreSdkScript({ | ||
| environment: "sandbox", | ||
| debug: true, | ||
| }); | ||
| } catch (err) { | ||
| throw new Error(`Failed to load the paypal sdk script: ${err}`); | ||
| } | ||
|
|
||
| if (!paypal?.createInstance) { | ||
| throw new Error("Invalid paypal object for v6"); | ||
| } | ||
|
|
||
| if (!paypal?.version) { | ||
| throw new Error("PayPal v6 namespace missing version property"); | ||
| } | ||
|
|
||
| const sdkInstance = await paypal.createInstance({ | ||
| clientToken: "fakeValue", | ||
| components: ["card-fields"], | ||
| }); | ||
|
|
||
| const paymentMethods = await sdkInstance.findEligibleMethods({ | ||
| currencyCode: "USD", | ||
| }); | ||
|
|
||
| if (!paymentMethods.isEligible("advanced_cards")) { | ||
| return; | ||
| } | ||
|
|
||
| const details = paymentMethods.getDetails("advanced_cards"); | ||
| details.supportsInstallments; | ||
| details.cobrandedEnabled; | ||
| details.vendors[0].network; | ||
| details.vendors[0].eligible; | ||
| details.vendors[0].canBeVaulted; | ||
| details.vendors[0].branded; | ||
|
|
||
| const paypalCardFieldsOneTimePaymentSession = | ||
| sdkInstance.createCardFieldsOneTimePaymentSession(); | ||
| paypalCardFieldsOneTimePaymentSession.createCardFieldsComponent({ | ||
| type: "number", | ||
| placeholder: "Enter a number:", | ||
| }); | ||
| paypalCardFieldsOneTimePaymentSession.createCardFieldsComponent({ | ||
| type: "cvv", | ||
| placeholder: "Enter CVV:", | ||
| }); | ||
| paypalCardFieldsOneTimePaymentSession.createCardFieldsComponent({ | ||
| type: "expiry", | ||
| placeholder: "Enter Expiry:", | ||
| }); | ||
|
|
||
| const createOrder = () => Promise.resolve({ orderId: "ABC123" }); | ||
|
|
||
| const submitButton = document.createElement("button"); | ||
| submitButton.addEventListener("click", async () => { | ||
| try { | ||
| const { orderId } = await createOrder(); | ||
| await paypalCardFieldsOneTimePaymentSession.submit(orderId); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add more tests to confirm those added types are there? For eg if (paymentMethods.isEligible("advanced_cards")) {
const details = paymentMethods.getDetails("advanced_cards");
console.log(details.supportsInstallments);
console.log(details.cobrandedEnabled);
console.log(details.vendors[0].network);
console.log(details.vendors[0].eligible);
console.log(details.vendors[0].can_be_vaulted);
console.log(details.vendors[0].branded);
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great callout. Added this tests! |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see
can_be_vaultedbelow, does this type require something similar?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can_be_vaultedis only part of thevendorsarray.