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

feature(payments-plugin): PayPal two-step flow implementation #3099

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

sonntag-philipp
Copy link
Contributor

@sonntag-philipp sonntag-philipp commented Oct 1, 2024

Description

This PR introduces a PayPal payments plugin based on the PayPal Orders Api with a 2 step flow as specified in the Vendure documentation.

The main purpose of this plugin is to offer the user a solution where PayPal can be used directly without a step in between.

Documentation will be added by me before this plugin is merged. Just want to make sure I don't have to change it after review feedback of the implementation.

Breaking changes

I am not able to determine a breaking change. The implemented features represent new functionality and should have no effect on existing implementations.

Overview

  • Only supports 2 step payments
  • Dev server contains ui that can be used to test payments
  • A single mutation is added to create PayPal orders
  • Integration and unit tests were added and should cover most of the functionality

Screenshots

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

+ Added types for PayPal REST Api
+ Added GraphQL code for PayPal Payment provider
+ Added PayPal handler
+ Added PayPal service for REST requests
+ Added PayPal helper for order mutations and validations
* Switched to args based configuration instead of VendureConfig
* Created new types for PayPalSdkPlugin to debug server
* Some cleanup of not used imports
Copy link

vercel bot commented Oct 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Oct 11, 2024 7:42pm

* Provided better error message in various cases
* Better overview of mocked data using fixtures file
* Integrating logger with logger ctx of the plugin
@sonntag-philipp sonntag-philipp changed the title Feature/payments plugin paypal feature(payments-plugin): Create PayPal integration without Braintree Oct 8, 2024
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'm not quite sure if most of the maintainers use WebStorm, but this makes it way easier to execute a specific test file in VSCode.

Also had to make some changes to the get-package-dir to make it work not only for the e2e within the payments-plugin.

});

// eslint-disable-next-line no-console
console.log('Auth Token: ', shopClient.getAuthToken());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This token is printed, so we can enter it in the Web UI of the paypal plugin. I would be open to setting this automatically in the Vendure REST Endpoint, but I wasn't quite sure how.

}

// @ts-ignore
function html(strings, ...values) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well. I know we shouldn't integrate code only for syntax highlighting, but as this isn't code of the library itself and only exists for testing purposes, one could argue that it's still okay.
Especially as it doesn't require additional dependencies.

@sonntag-philipp
Copy link
Contributor Author

I still have to implement the idempotency headers supported by the PayPal Api, even though it already works without them. This could also be done is a future PR.

+ Added unit tests for paypal order helper
@sonntag-philipp sonntag-philipp changed the title feature(payments-plugin): Create PayPal integration without Braintree feature(payments-plugin): PayPal two-step flow implementation Oct 10, 2024
@sonntag-philipp sonntag-philipp marked this pull request as ready for review October 10, 2024 14:12
throw new Error('Please provide PayPal credentials in the .env file');
}

const apiUrl = 'https://api-m.sandbox.paypal.com';
Copy link
Contributor

Choose a reason for hiding this comment

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

I know its probably unlikely for paypal to change their sandbox URL but it could prove useful to get this URL also from the .env with the current value as default.

Comment on lines +28 to +33
if (!sessionOrder) {
throw new IllegalOperationError('Session has no active order');
}
if (sessionOrder.state !== 'ArrangingPayment') {
throw new IllegalOperationError('Order must be in arranging payment state');
}
Copy link
Contributor

@DanielBiegler DanielBiegler Oct 13, 2024

Choose a reason for hiding this comment

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

I think these could be internationalized with existing error message for example there are:

    "NO_ACTIVE_ORDER_ERROR": "There is no active Order associated with the current session",

and

    "ORDER_MODIFICATION_ERROR": "Order contents may only be modified when in the \"AddingItems\" state",
    "ORDER_PAYMENT_STATE_ERROR": "A Payment may only be added when Order is in \"ArrangingPayment\" state",
    "ORDER_STATE_TRANSITION_ERROR": "Cannot transition Order from \"{ fromState }\" to \"{ toState }\"",

Might be good to take a second pass over all thrown errors and see what can be internationalized and reused.

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.

3 participants