-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
The payment provider paypal is of type PaymentProcessor. PaymentProcessors cannot update payment session data. #4166
Comments
I wrote custom payment provider called StripeExtended which i am having same problem. /services/stripe-extended.ts import {
CartService,
CustomerService,
PaymentProcessorContext,
PaymentProcessorError,
PaymentProcessorSessionResponse,
PaymentSessionStatus,
} from "@medusajs/medusa";
import { AbstractPaymentProcessor } from "@medusajs/medusa/dist/interfaces/payment-processor";
import Stripe from "stripe";
class StripeExtended extends AbstractPaymentProcessor {
static identifier: string = "StripeExtended";
public stripe_: Stripe;
protected customerService_: CustomerService;
protected cartService_: CartService;
protected stripeOptions: {
secret_key: string;
success_url: string;
options: Record<string, unknown>;
};
constructor(container, _options) {
super(container);
// ...
}
// ... POST /stripe/hook API // ...
await cartServiceTx.setPaymentSessions(cart.id);
await cartServiceTx.setPaymentSession(cart.id, "StripeExtended");
await cartServiceTx.updatePaymentSession(cart.id, {
...checkout,
});
// ...
also could be related with #4124 |
Can we have an update on this please ? 🙏 Seems linked to #3722 and #4076 Maybe it's just unclear in the documentation why it is required for some PaymentProcessor and not for others. And if it's not needed for Paypal, it should be removed from the example in the documentation PS: In the NextJs storefront it seems that the |
What payment session are you trying to update? I would like to understand a bit more about what needs to be updated in the payment flow. As far as I can see, everything should be up to date in the payment provider no? Also, if by any chance the customer goes back to the store to update his cart, the payment will be updated with the updated amount |
Hi @adrien2p , This piece of code come from the Medusa Paypal documentation
Maybe i missunderstood but for me at this moment, the payment is done, so the cart can be deleted and the order created. |
Is there any update here. On my checkout flow basically we send the CC to our payment processor and it returns a token that we must to send to our backend to process the payment in the backend but i'm having this issue when trying to set the token in the session |
I didn't checked once i found workaround but what i did was i wrote middleware which injects context to request which is then accessible inside payment processor as context argument |
I'm writing a payment provider that uses hosted checkout. When the call to completeCart returns REQUIRES_MORE, I use the hosted checkout URL stored in the payment session to redirect the user to the payment provider's hosted checkout page. When the user comes back, I need to update the payment session to reflect the authorized status from the external checkout process. How do you see that working if updatePaymentSession is not the supported use case here? Further, looking at this code: async updateSessionData(
paymentSession: PaymentSession,
data: Record<string, unknown>
): Promise<PaymentSession> {
return await this.atomicPhase_(async (transactionManager) => {
const session = await this.retrieveSession(paymentSession.id)
const provider = this.retrieveProvider(paymentSession.provider_id)
if (provider instanceof AbstractPaymentProcessor) {
throw new MedusaError(
MedusaError.Types.NOT_ALLOWED,
`The payment provider ${paymentSession.provider_id} is of type PaymentProcessor. PaymentProcessors cannot update payment session data.`
)
} else {
session.data = await provider
.withTransaction(transactionManager)
.updatePaymentData(paymentSession.data, data)
session.status = paymentSession.status
}
const sessionRepo = transactionManager.withRepository(
this.paymentSessionRepository_
)
return await sessionRepo.save(session)
})
} Is there ever a scenario where provider would not be expected to be an instance of AbstractPaymentProcessor? I'm trying to understand the purpose of this check and how to work around it. |
working on it #4442 |
Awesome, thanks! For what it's worth, I ended up dropping into low level code using the paymentSessionRepository to update the record directly. I know this probably isn't recommended, but I didn't have any other way to complete the task at the time. In my web hook subscriber: private async getPaymentSession(checkoutSessionId: string): Promise<PaymentSession> {
return await this.paymentSessionRepository
.createQueryBuilder('payment_session')
.where(`payment_session.data->>'checkoutSessionId' = :checkoutSessionId`, {
checkoutSessionId,
})
.getOneOrFail();
}
private async handleAuthorized(data: PaymentWebHook): Promise<void> {
const session = await this.getPaymentSession(data.checkoutSessionId);
await this.paymentSessionRepository.save({
...session,
data: {
...session.data,
status: 'authorized',
} as CheckoutSessionData as any,
});
} |
If we publish a snapshot with the changes in #4442, can one of you confirm that everything works as expected on your side? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
This issue was closed because it has been stalled for 3 days with no activity. |
Bug report
Describe the bug
I am following the Checkout Flow with the PayPal plugin but I get the following JSON when I reach the Update Payment Session step.
Code
Request
http://localhost:9000/store/carts/cart_01H16S35WZ6AJ8F76KF2B78CYE/payment-sessions/paypal
Response
System information
Medusa version (including plugins):
Backend
Frontend
Node.js version: v18.15.0
Database: PostgreSQL (v15.3)
Operating system: macOs Monterey (Version 12.5)
Browser (if relevant): Google Chrome (Version 113.0.5672.126)
Steps to reproduce the behavior
Expected behavior
It should update the Payment Session inside the Cart object without errors.
Code snippets
Checkout code
PayPal.tsx
Context
I correctly loaded the PayPal plugin inside the Region through the Admin Panel.
The text was updated successfully, but these errors were encountered: