lolmx / Stripe

[READ-ONLY] Subtree split of the Payum Stripe Component -- clone into Payum/Stripe/ (master at payum/payum)
https://payum.forma-pro.com/
MIT License
5 stars 6 forks source link

Wrong parameters #9

Open Arvi89 opened 4 years ago

Arvi89 commented 4 years ago

Hello, I've used your last fix, but when I want to pay, somehow it get a 400 from stripe. In the logs from their console, I can see that "POST /v1/payment_methods" is being called, with weird parameters:

{ "0": { "jQuery1111027840744389734773": "1" }, "type": "card", "context": { "jQuery1111027840744389734773": "1" }, "length": "1", "guid": "081e87d0-97cb-497f-b7d0-882ab266c439", "muid": "9bd6e6a1-b3bb-4c29-908b-e0e1a2b0c0e6", "sid": "914682ec-7c70-4972-a0d7-1ae8815a0632", "payment_user_agent": "stripe.js/854c6379; stripe-js-v3/854c6379", "referrer": "http://127.0.0.1:8000/fr/payment/capture/q_c9wydB_4mvrRKGJ5eLo-7fOuwCNJ8n1L3fXJf8mFs", "key": "pk_test_TV****GLUF" }

And stripe doesn't know what to do with that.

hschiebold commented 4 years ago

same for me - and only with StripeJsGatewayFactory - with StripeCheckoutGatewayFactory it is the old stuff with obtain_checkout_token.html.twig and did not working

i am using a zend framework

first defining payum gateways:

'gateways' => array( 'paypal_ec' => (new Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory())->create(array( 'username' => 'holger.schiebold...', 'password' => '...', 'signature' => '...', 'sandbox' => true )), 'stripe' => (new Payum\Stripe\StripeCheckoutGatewayFactory())->create(array( 'publishable_key' => 'pktest...', 'secret_key' => 'sktest...', 'sca_flow' => true )) ),

second prepare in controller:

payment checkout

        $storage = $this->getServiceLocator()->get('payum')->getStorage('Application\Model\PaymentDetails');
        $details = $storage->create();
        $booking->setMeta('directpay', 'true');
        $bookingManager->save($booking);
        #paypal checkout
        if ($payservice == 'paypal') {
            $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
            $details['PAYMENTREQUEST_0_AMT'] = $total/100;
            $details['PAYMENTREQUEST_0_BID'] = $booking->get('bid');
            $storage->update($details);
            $captureToken = $this->getServiceLocator()->get('payum.security.token_factory')->createCaptureToken(
                'paypal_ec', $details, 'square/booking/payment_done');
            return $this->redirect()->toUrl($captureToken->getTargetUrl());
        }
        #paypal checkout
        #stripe checkout
        if ($payservice == 'stripe') {
            $details["amount"] = $total;
            $details["currency"] = 'EUR';
            $details["description"] = 'tvas booking-'.$booking->get('bid');
            $storage->update($details);
            $captureToken = $this->getServiceLocator()->get('payum.security.token_factory')->createCaptureToken(
                'stripe', $details, 'square/booking/payment_done');
            return $this->redirect()->toUrl($captureToken->getTargetUrl());
        }
        #stripe checkout

payment checkout

last done action:

$token = $this->getServiceLocator()->get('payum.security.http_request_verifier')->verify($this); \PaymentDetails');

    $gateway = $this->getServiceLocator()->get('payum')->getGateway($token->getGatewayName());

    $gateway->execute($status = new GetHumanStatus($token));
hschiebold commented 4 years ago

same for me - and only with StripeJsGatewayFactory - with StripeCheckoutGatewayFactory it is the old stuff with obtain_checkout_token.html.twig and did not working

i am using a zend framework

first defining payum gateways:

'gateways' => array( 'paypal_ec' => (new Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory())->create(array( 'username' => 'holger.schiebold...', 'password' => '...', 'signature' => '...', 'sandbox' => true )), 'stripe' => (new Payum\Stripe\StripeCheckoutGatewayFactory())->create(array( 'publishable_key' => 'pktest...', 'secret_key' => 'sktest...', 'sca_flow' => true )) ),

second prepare in controller:

payment checkout

        $storage = $this->getServiceLocator()->get('payum')->getStorage('Application\Model\PaymentDetails');
        $details = $storage->create();
        $booking->setMeta('directpay', 'true');
        $bookingManager->save($booking);
        #paypal checkout
        if ($payservice == 'paypal') {
            $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
            $details['PAYMENTREQUEST_0_AMT'] = $total/100;
            $details['PAYMENTREQUEST_0_BID'] = $booking->get('bid');
            $storage->update($details);
            $captureToken = $this->getServiceLocator()->get('payum.security.token_factory')->createCaptureToken(
                'paypal_ec', $details, 'square/booking/payment_done');
            return $this->redirect()->toUrl($captureToken->getTargetUrl());
        }
        #paypal checkout
        #stripe checkout
        if ($payservice == 'stripe') {
            $details["amount"] = $total;
            $details["currency"] = 'EUR';
            $details["description"] = 'tvas booking-'.$booking->get('bid');
            $storage->update($details);
            $captureToken = $this->getServiceLocator()->get('payum.security.token_factory')->createCaptureToken(
                'stripe', $details, 'square/booking/payment_done');
            return $this->redirect()->toUrl($captureToken->getTargetUrl());
        }
        #stripe checkout

payment checkout

last done action:

$token = $this->getServiceLocator()->get('payum.security.http_request_verifier')->verify($this); \PaymentDetails');

    $gateway = $this->getServiceLocator()->get('payum')->getGateway($token->getGatewayName());

    $gateway->execute($status = new GetHumanStatus($token));
hschiebold commented 4 years ago

additionally with sca_flow = 'false' all is working well with stripe checkout

lolmx commented 4 years ago

Can you show me your js pls?

hschiebold commented 4 years ago

Hi Eric,

I do nothing else than the above code. The js should come from the used template in the Payum/Stripe module. When using above code with this lolmx/Stripe module and sca_flow = 'false' and the StripeCheckoutGatewayFactory than all works well. Only with sca_flow = 'true' it seems that the "old" template does not work together with the new PaymentIntent API.

regards Holger

hschiebold commented 4 years ago

Hi Eric,

i tried again using the JsFactory and got it working with a bit modifying my template - but never reached the ConfirmAction or the RequireConfirmationAction with sca test cards from stripe. Do i have to do anything else in my done action then $gateway->execute($status = new GetHumanStatus($token)); ?

thanks in advance Holger

hschiebold commented 4 years ago

@lolmx

got it working using js templates and extending my code with a confirm action. Thanks for your work.

regards Holger

magedan commented 4 years ago

Hello,

I'm facing same issue as in the first post, Stripe responds with 400 status code with the following JSON body:

{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameters: 0, context, length",
    "param": "0",
    "type": "invalid_request_error"
  }
}

@hschiebold could you please share your updates? I'm on master branch btw.

magedan commented 4 years ago

I managed to get Stripe working on client side with these minor modifications to the obtain_js_token_for_strong_customer_authentication.html.twig:

        jQuery(function($) { 
           // This identifies your website in the call below
            var stripe = Stripe({{ publishable_key|json_encode|raw }});

            // Create an instance of the card Element.
            var elements = stripe.elements();
            var card = elements.create('card');

            // Add an instance of the card Element into the `card-element` <div>.
            card.mount('#card-element');

            $('#payment-form').submit(function(e) {
                var $form = $(this);

                // Disable the submit button to prevent repeated clicks
                $form.find('button').prop('disabled', true);

                stripe.createPaymentMethod({
                    type: 'card',
                    card: card
                }).then(stripeResponseHandler);

                // Prevent the form from submitting with the default action
                return false;
            });

            var stripeResponseHandler = function(response) {
                var $form = $('#payment-form');

                if (response.error) {
                    // Show the errors on the form
                    $form.find('.payment-errors').text(response.error.message);
                    $form.find('button').prop('disabled', false);
                } else {
                    // token is the created payment method's id
                    var token = response.paymentMethod.id;

                    // Insert the token into the form so it gets submitted to the server
                    $form.append($('<input type="hidden" name="stripeToken" />').val(token));
                    // and re-submit
                    $form.get(0).submit();
                }
            };
        });

However, when I try to use testing card with SCA enabled I always get "unknown" status here $gateway->execute($status = new GetHumanStatus($token));. Same for 3D secured cards. With "normal" cards everything seems fine.

@lolmx could you please give any suggestions how to proceed with the SCA card payment? Would be glad to share any additional information regarding my Payum config, but basically I just followed your guide here.

hschiebold commented 4 years ago

@magedan you will find my js template (vendor/payum/stripe/Payum/Stripe/Resources/views/Action/stripe_js.html.twig) in the fork of the booking system for our tennis indoor court at https://github.com/hschiebold/ep3-bs

the tempate is inspired by the stripe payments demo (https://github.com/stripe/stripe-payments-demo) and uses apple pay / google pay via stripe too

im am using payum module for the zend framwork and extended it with a confrim action so the sca workflow was working for me

magedan commented 4 years ago

@hschiebold thanks a lot! Basically, the same modifications with "elements" as I have found so far.

@lolmx do you think this should lead to PR? I'm not really familiar with Stripe/Payum, just need to get it working..

jimiero commented 4 years ago

@lolmx do you have some documentation on how to use your plugin, as I have the same error as reported here

jimiero commented 4 years ago

A token may not be passed in as a PaymentMethod. Instead, use payment_method_data with type=card and card[token]=tok_1GcuFvHQU2xxxxxXWH2FMNje.

jimiero commented 4 years ago

After some more play around, i get this error when click submit payment button:

You cannot create a charge with a PaymentMethod. Use the Payment Intents API instead