-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(payments-plugin, stripe): Export StripeService to support more payment flows #3624
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
feat(payments-plugin, stripe): Export StripeService to support more payment flows #3624
Conversation
WalkthroughThe changes introduce a new Vendure test plugin and related GraphQL mutation to facilitate custom Stripe payment intent creation, update test infrastructure to utilize this mutation, and adjust plugin exports for service accessibility. Additional modifications include import path corrections and code cleanup, without altering existing logic or control flow. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ShopAPI
participant CustomStripeResolver
participant OrderService
participant RequestContextService
participant StripeService
Client->>ShopAPI: createCustomStripePaymentIntent(orderCode, channelToken)
ShopAPI->>CustomStripeResolver: invoke mutation resolver
CustomStripeResolver->>OrderService: findOneByCode(ctx, orderCode)
OrderService-->>CustomStripeResolver: return Order or null
alt Order found
CustomStripeResolver->>RequestContextService: create({ channelOrToken: channelToken })
RequestContextService-->>CustomStripeResolver: return customCtx
CustomStripeResolver->>StripeService: createPaymentIntent(customCtx, order)
StripeService-->>CustomStripeResolver: return paymentIntent
CustomStripeResolver-->>ShopAPI: return paymentIntent
ShopAPI-->>Client: return paymentIntent
else Order not found
CustomStripeResolver-->>ShopAPI: throw error
ShopAPI-->>Client: error
end
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
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.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/payments-plugin/e2e/fixtures/stripe-checkout-test.plugin.ts
(1 hunks)packages/payments-plugin/e2e/fixtures/stripe-service-export-test.plugin.ts
(1 hunks)packages/payments-plugin/e2e/payment-helpers.ts
(1 hunks)packages/payments-plugin/e2e/stripe-dev-server.ts
(3 hunks)packages/payments-plugin/src/stripe/stripe.plugin.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/payments-plugin/e2e/stripe-dev-server.ts (3)
packages/payments-plugin/e2e/payment-helpers.ts (1)
CREATE_CUSTOM_STRIPE_PAYMENT_INTENT
(232-236)packages/core/src/config/logger/vendure-logger.ts (1)
Logger
(136-204)packages/payments-plugin/e2e/fixtures/stripe-service-export-test.plugin.ts (1)
createCustomStripePaymentIntent
(27-45)
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: e2e tests (20.x, postgres)
- GitHub Check: codegen / codegen
- GitHub Check: e2e tests (22.x, mariadb)
- GitHub Check: e2e tests (22.x, postgres)
- GitHub Check: e2e tests (20.x, mariadb)
- GitHub Check: e2e tests (22.x, mysql)
- GitHub Check: e2e tests (20.x, mysql)
- GitHub Check: e2e tests (22.x, sqljs)
- GitHub Check: e2e tests (20.x, sqljs)
- GitHub Check: unit tests (20.x)
- GitHub Check: build (22.x)
- GitHub Check: build (20.x)
- GitHub Check: unit tests (22.x)
- GitHub Check: publish_install (windows-latest, 22.x)
- GitHub Check: publish_install (macos-latest, 22.x)
- GitHub Check: publish_install (macos-latest, 20.x)
- GitHub Check: publish_install (windows-latest, 20.x)
- GitHub Check: publish_install (ubuntu-latest, 20.x)
- GitHub Check: publish_install (ubuntu-latest, 22.x)
🔇 Additional comments (4)
packages/payments-plugin/src/stripe/stripe.plugin.ts (1)
200-200
: LGTM! Clean implementation of the core feature.The export of
StripeService
enables the desired functionality for custom payment flows while maintaining backward compatibility. This change directly addresses the PR objectives.packages/payments-plugin/e2e/fixtures/stripe-checkout-test.plugin.ts (1)
2-2
: LGTM! Import cleanup and path correction.The import reordering and path correction are good housekeeping changes that maintain proper project structure.
Also applies to: 6-6
packages/payments-plugin/e2e/stripe-dev-server.ts (1)
20-21
: LGTM! Proper test plugin integration.The new test plugins are correctly imported and integrated into the test environment, enabling proper testing of the exported StripeService functionality.
Also applies to: 29-33, 53-53
packages/payments-plugin/e2e/fixtures/stripe-service-export-test.plugin.ts (1)
27-44
: Excellent demonstration of the exported StripeService usage.The resolver effectively showcases how to use the exported
StripeService
for custom payment flows, including:
- Cross-channel payment support via custom request context
- Flexible order lookup by code
- Proper service injection and usage
This implementation aligns perfectly with the PR objectives and provides a valuable example for developers.
export const CREATE_CUSTOM_STRIPE_PAYMENT_INTENT = gql` | ||
mutation createCustomStripePaymentIntent { | ||
createCustomStripePaymentIntent | ||
} | ||
`; |
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.
Fix argument mismatch in GraphQL mutation.
The mutation definition is missing the required arguments that the resolver expects. Based on the StripeServiceExportTestPlugin
, the mutation should include orderCode
and channelToken
parameters.
Apply this fix to match the resolver implementation:
-export const CREATE_CUSTOM_STRIPE_PAYMENT_INTENT = gql`
- mutation createCustomStripePaymentIntent {
- createCustomStripePaymentIntent
- }
-`;
+export const CREATE_CUSTOM_STRIPE_PAYMENT_INTENT = gql`
+ mutation createCustomStripePaymentIntent($orderCode: String!, $channelToken: String!) {
+ createCustomStripePaymentIntent(orderCode: $orderCode, channelToken: $channelToken)
+ }
+`;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export const CREATE_CUSTOM_STRIPE_PAYMENT_INTENT = gql` | |
mutation createCustomStripePaymentIntent { | |
createCustomStripePaymentIntent | |
} | |
`; | |
export const CREATE_CUSTOM_STRIPE_PAYMENT_INTENT = gql` | |
mutation createCustomStripePaymentIntent($orderCode: String!, $channelToken: String!) { | |
createCustomStripePaymentIntent(orderCode: $orderCode, channelToken: $channelToken) | |
} | |
`; |
🤖 Prompt for AI Agents
In packages/payments-plugin/e2e/payment-helpers.ts around lines 232 to 236, the
GraphQL mutation createCustomStripePaymentIntent is missing the required
arguments orderCode and channelToken that the resolver expects. Update the
mutation definition to include these parameters in the mutation signature and
pass them correctly in the mutation body to match the resolver implementation.
// Showcasing the custom intent creation | ||
const { createCustomStripePaymentIntent } = await shopClient.query(CREATE_CUSTOM_STRIPE_PAYMENT_INTENT); | ||
Logger.debug('Result of createCustomStripePaymentIntent:', createCustomStripePaymentIntent); | ||
|
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.
Fix missing arguments in mutation call.
The mutation call is missing the required orderCode
and channelToken
arguments that the resolver expects. This will cause a runtime error.
Apply this fix to provide the required arguments:
- // Showcasing the custom intent creation
- const { createCustomStripePaymentIntent } = await shopClient.query(CREATE_CUSTOM_STRIPE_PAYMENT_INTENT);
- Logger.debug('Result of createCustomStripePaymentIntent:', createCustomStripePaymentIntent);
+ // Showcasing the custom intent creation
+ const { createCustomStripePaymentIntent } = await shopClient.query(CREATE_CUSTOM_STRIPE_PAYMENT_INTENT, {
+ orderCode: 'T_1', // Use the order code from the test setup
+ channelToken: '__default_channel__', // Use the default channel token
+ });
+ Logger.debug('Result of createCustomStripePaymentIntent:', createCustomStripePaymentIntent);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Showcasing the custom intent creation | |
const { createCustomStripePaymentIntent } = await shopClient.query(CREATE_CUSTOM_STRIPE_PAYMENT_INTENT); | |
Logger.debug('Result of createCustomStripePaymentIntent:', createCustomStripePaymentIntent); | |
// Showcasing the custom intent creation | |
const { createCustomStripePaymentIntent } = await shopClient.query(CREATE_CUSTOM_STRIPE_PAYMENT_INTENT, { | |
orderCode: 'T_1', // Use the order code from the test setup | |
channelToken: '__default_channel__', // Use the default channel token | |
}); | |
Logger.debug('Result of createCustomStripePaymentIntent:', createCustomStripePaymentIntent); |
🤖 Prompt for AI Agents
In packages/payments-plugin/e2e/stripe-dev-server.ts around lines 108 to 111,
the mutation call to createCustomStripePaymentIntent is missing the required
orderCode and channelToken arguments expected by the resolver. Fix this by
passing an object with orderCode and channelToken properties as variables to the
shopClient.query call to ensure the mutation receives the necessary inputs and
avoids runtime errors.
schema: gql` | ||
extend type Mutation { | ||
createCustomStripePaymentIntent(orderCode: String, channelToken: String): String! | ||
} | ||
`, |
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.
🛠️ Refactor suggestion
Make GraphQL arguments required and improve error handling.
The arguments should be required since the resolver logic depends on them, and the error handling could be more descriptive.
Apply these improvements:
- extend type Mutation {
- createCustomStripePaymentIntent(orderCode: String, channelToken: String): String!
- }
+ extend type Mutation {
+ createCustomStripePaymentIntent(orderCode: String!, channelToken: String!): String!
+ }
Also improve error handling in the resolver:
- if (!order) {
- throw new Error('No order');
- }
+ if (!order) {
+ throw new Error(`Order with code "${args.orderCode}" not found`);
+ }
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/payments-plugin/e2e/fixtures/stripe-service-export-test.plugin.ts
around lines 51 to 55, the GraphQL mutation arguments orderCode and channelToken
are currently optional but should be required since the resolver depends on
them. Update the schema to make these arguments non-nullable by adding
exclamation marks. Additionally, enhance the resolver's error handling by
checking for the presence of these arguments explicitly and throwing descriptive
errors if they are missing, to improve clarity and debugging.
Thanks for going the extra step of demonstrating usage & fixing up the existing server implementation 👍 |
Description
In our app, we want to allow shop admins to make changes to customer orders which are no longer active. These changes might introduce the need to add additional payments to the order. In this case an order can be for example in the
ArrangingAdditionalPayment
state, and there we want to shift the payment to the customer.Primarily we use the existing stripe payment plugin, which works perfectly in regular order flows. Looking at the implementation details, the existing
StripeService
code could be reused to support our, and possibly other vendure plugin developer's needs.To do so, we just need to export the
StripeService
from the plugin.In the example plugin code below, I show an example
createCustomStripePaymentIntent
mutation, where I use theStripeService
intent creation with custom request context and order lookup.The change itself is a one-liner, a single plugin export. The fixture
./stripe-service-export-test.plugin.ts
and additional file changes are only there to explain what I am after.Let me know if this change is acceptable and works with the codebase. Right now I'm using a patch-package fix to work around the missing export.
Breaking changes
No breaking change.
Screenshots
You can add screenshots here if applicable.
Checklist
📌 Always:
👍 Most of the time:
Summary by CodeRabbit
New Features
Improvements
Chores