Wittner
Wittner

Reputation: 593

Stripe payments, cannot get payment amount from checkout

I'm using Stripe 'checkout' to collect payments. I have used this successfully on other sites but this particular use-case is slightly different from my normal flow and is causing me problems. My customer sometimes has a choice to pay deposit or full payment. I present two buttons in this case, one for each payment type e.g.

<form name="myform" action="paymentpage.php">
... other form stuff
    <!-- Deposit payment button Stripe -->
    <script
      src="https://checkout.stripe.com/checkout.js" class="stripe-button"
      data-key="abcd"
      data-amount="10000"
      data-name="My company name"
      data-description="Deposit payment"
      data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
      data-locale="auto"
      data-zip-code="true"
      data-currency="eur"
      data-label="Pay Deposit">
    </script>
    <!-- Full payment button Stripe -->
    <script
      src="https://checkout.stripe.com/checkout.js" class="stripe-button"
      data-key="avcd"
      data-amount="{{ $stripeCostValue }}"
      data-name="My company name"
      data-description="Full payment"
      data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
      data-locale="auto"
      data-zip-code="true"
      data-currency="eur"
      data-label="Pay in full">
    </script>

I want to use cURL to make the charge after the customer has done their bit e.g.

curl https://api.stripe.com/v1/charges \
   -u sk_liveabcd1234: \
   -d amount=1000 \
   -d currency=eur \
   -d description="Deposit payment" \
   -d source=tok_89797oioououo

The Laravel controller which receives the posted data has the following Stripe fields included by default:

"stripeToken" => "tok_89797oioououo"
"stripeTokenType" => "card"
"stripeEmail" => "[email protected]"

But I have no idea whether they paid a deposit, full payment, or the amount they paid. Is there a way I am supposed to know which button they pressed or is there a way to get more data from the Stripe payment? I can't figure it out. I can't include the amount or payment type as a hidden field because I don't know which payment button the customer will push.

Thanks in advance

Upvotes: 0

Views: 804

Answers (1)

koopajah
koopajah

Reputation: 25552

The issue is that you put both buttons in the same form. Because of this you don't know which one is clicked.

The easiest solution is to simply have 2 separate buttons and forms. That way, in each form you can put a hidden field that lets you know which button was clicked as the value gets submitted with the form.

Another solution is to use Custom Checkout. This lets you have 2 separate buttons in your form and, in JS, add a handler to open Checkout on click. This also lets you easily track which button was clicked and then submit this information to your server once the token is created.

Upvotes: 1

Related Questions