Skip to content
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

Introduce env parameter to support sandbox and paypal #485

Merged
merged 10 commits into from
Apr 17, 2024
Merged

Conversation

ravishekhar
Copy link
Contributor

  • Introduce a new option in the loadScript method to allow passing env = sandbox or production.
  • If env=sandbox is passed as an option, then the sdk script will be loaded from www.sandbox.paypal.com/sdk/js

Copy link

changeset-bot bot commented Apr 15, 2024

🦋 Changeset detected

Latest commit: 014d1a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@paypal/paypal-js Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@nbierdeman nbierdeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small nitpicks, but LGTM. 🚀

packages/paypal-js/src/utils.ts Outdated Show resolved Hide resolved
packages/paypal-js/types/script-options.d.ts Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
Copy link
Member

@jshawl jshawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 1 small non-blocking suggestion. :shipit:

packages/paypal-js/src/utils.ts Outdated Show resolved Hide resolved
ravishekhar and others added 2 commits April 15, 2024 13:59
@ravishekhar ravishekhar marked this pull request as ready for review April 15, 2024 20:27
@ravishekhar ravishekhar requested a review from a team as a code owner April 15, 2024 20:27
@@ -21,6 +21,7 @@ interface PayPalScriptQueryParameters {
}

interface PayPalScriptDataAttributes {
env?: "sandbox" | "production";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravishekhar I'm still seeing the name as env in the diff. Can we update to environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I see my git push got denied earlier. Just did that again. Thanks for catching this.

… env-option

# Conflicts:
#	packages/paypal-js/src/utils.ts
@@ -104,6 +104,13 @@ function validateArguments(options: unknown, PromisePonyfill?: unknown) {
if (typeof options !== "object" || options === null) {
throw new Error("Expected an options object.");
}
const { environment } = options as PayPalScriptOptions;

if (environment && !["production", "sandbox"].includes(environment)) {
Copy link
Contributor

@gregjopa gregjopa Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to remove this validation code for two reasons:

  1. The logic in utils.ts will ignore any bad values and will default the production environment.
  2. paypal-js is designed to compile to ES3 so using Array.prototype.includes() would be a breaking change. If we really want to keep this, let's replace the usage of includes() with something that transpiles nicely to ES3 and does not require a polyfill.

This loader is meant to be as small as possible on top of the PayPal JS SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the challenges with Array.prototype.includes() . We can definitely use an alternative there 👍 .

About not having validations on input, once production stops the support for sandbox, then this may become a source of errors, if there is any typos in the input options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. Let's replace the usage of Array.prototype.includes() with some old school JS then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ✔️

@gregjopa gregjopa merged commit c0badf3 into main Apr 17, 2024
3 checks passed
@gregjopa gregjopa deleted the env-option branch April 17, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants