Git Product home page Git Product logo

payumstripebundle's Introduction

CoreShop Stripe Payum Connector

This Bundle activates the Stripe Checkout & Stripe JS Payment Gateways in CoreShop. It requires the FLUX-SE/PayumStripe repository which will be installed automatically.

Installation

1. Composer

    "coreshop/payum-stripe-bundle": "^2.0"

2. Activate

Enable the Bundle in Pimcore Extension Manager

3. Setup

Go to Coreshop -> PaymentProvider and add a new Provider. Choose stripe_checkout/stripe_js from type and fill out the required fields.

payumstripebundle's People

Contributors

dpfaffenbauer avatar mkrempel avatar ramundomario avatar rberneder avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

payumstripebundle's Issues

Webhook Status not updating

Not sure if even someone here is maintaining or using this repository (@dpfaffenbauer, @ramundomario, @BlackbitDevs) - I've already forked this repo a while ago, and I'll also fix it there. Since this took my a full day of debugging/hunting/reading/comparing, you might be interested:

If you're using payments like SOFORT / Klarna, you need to rely on webhooks because payments gets authorized only first. But there are two issues with CoreShop:

I. Order never gets in confirmed state

This is a fundamental problem of CoreShop, I'll open a dedicated ticket for that on CoreShop side.

The user never reaches the success page, because stripe returns with state processing which is not a "success" state in CoreShop:

https://github.com/coreshop/CoreShop/blob/a1a456fdefaa259f791cc3a0b04c05be183948e5/src/CoreShop/Bundle/PayumBundle/Action/ResolveNextRouteAction.php#L44-L45

(and other two places)

Reference: In Sylius they already made some adjustment to handle processing/pending payments:

II. Payment State not updating

If stripe dispatches the checkout.session.async_payment_succeeded webhook, the payment details will be updated but not the payment state => I have no Idea why. I've fixed it by adding an extension which is basically the same as SyliusPayumStripePlugin is using:

https://github.com/FLUX-SE/SyliusPayumStripePlugin/blob/master/src/Extension/UpdatePaymentStateExtension.php

<?php

use CoreShop\Bundle\PayumBundle\Factory\GetStatusFactoryInterface;
use CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManager;
use CoreShop\Component\Core\Model\PaymentInterface;
use CoreShop\Component\Payment\PaymentTransitions;
use CoreShop\Component\Payment\Repository\PaymentRepositoryInterface;
use Payum\Core\Extension\Context;
use Payum\Core\Extension\ExtensionInterface;
use Payum\Core\Model\ModelAggregateInterface;
use Payum\Core\Storage\IdentityInterface;

final class UpdatePaymentStateExtension implements ExtensionInterface
{
    private $scheduledPaymentsToProcess = [];

    public function __construct(
        private StateMachineManager $stateMachineManager,
        private PaymentRepositoryInterface $paymentRepository,
        private GetStatusFactoryInterface $getStatusRequestFactory
    ) {
    }

    public function onPreExecute(Context $context): void
    {
        /** @var mixed|ModelAggregateInterface $request */
        $request = $context->getRequest();

        if (false === $request instanceof ModelAggregateInterface) {
            return;
        }

        if ($request->getModel() instanceof IdentityInterface) {
            $payment = $this->paymentRepository->find($request->getModel()->getId());
        } else {
            /** @var PaymentInterface|mixed $payment */
            $payment = $request->getModel();
        }

        if (false === $payment instanceof PaymentInterface) {
            return;
        }

        $this->scheduleForProcessingIfSupported($payment);
    }

    public function onExecute(Context $context): void
    {
    }

    public function onPostExecute(Context $context): void
    {
        if (null !== $context->getException()) {
            return;
        }

        /** @var mixed|ModelAggregateInterface $request */
        $request = $context->getRequest();

        if ($request instanceof ModelAggregateInterface) {
            /** @var PaymentInterface|mixed $payment */
            $payment = $request->getModel();
            if ($payment instanceof PaymentInterface) {
                $this->scheduleForProcessingIfSupported($payment);
            }
        }

        if (count($context->getPrevious()) > 0) {
            return;
        }

        // Process scheduled payments only when we are post executing a
        // root payum request
        foreach ($this->scheduledPaymentsToProcess as $id => $payment) {
            $this->processPayment($context, $payment);
            unset($this->scheduledPaymentsToProcess[$id]);
        }
    }

    private function processPayment(Context $context, PaymentInterface $payment): void
    {
        $status = $this->getStatusRequestFactory->createNewWithModel($payment);
        $context->getGateway()->execute($status);
        /** @var string $value */
        $value = $status->getValue();
        if ($payment->getState() === $value) {
            return;
        }

        if (PaymentInterface::STATE_UNKNOWN === $value) {
            return;
        }

        $this->updatePaymentState($payment, $value);
    }

    private function scheduleForProcessingIfSupported(PaymentInterface $payment): void
    {
        $id = $payment->getId();
        if (null === $id) {
            return;
        }

        if (false === is_int($id)) {
            return;
        }

        $this->scheduledPaymentsToProcess[$id] = $payment;
    }

    private function updatePaymentState(PaymentInterface $payment, string $nextState): void
    {
        $workflow = $this->stateMachineManager->get($payment, PaymentTransitions::IDENTIFIER);
        if (null !== $transition = $this->stateMachineManager->getTransitionToState($workflow, $payment, $nextState)) {
            $workflow->apply($payment, $transition);
        }
    }
}

Enhancement proposal

Hi @ramundomario,

Would you be interested into having some abstract class or services into this https://github.com/FLUX-SE/PayumStripeBundle, to avoid copying all *Provider from the Sylius Plugin.
I think we can make something less painful for you and maybe more efficient if the core *Provider would be available into a root bundle (or into the root library).

What do you think about it ?

[Stripe Checkout] Adjustments are ignored

Adjustments are ignored by the stripe payment bundle. If you do have a coreshop cart price rule, for example a coupon, which does reduce the price of the order, the subtotal value will be send to stripe instead of the total value.
This sample:
adjustments

Will deduct 168 Euro (subtotal gross) of the credit card. Should be 151,2 Euro.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.