Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I generate a payment URL with Stripe Checkout?

I'd like to create a URL that I can share in my newsletter that sends people directly to a Stripe Checkout form to make a small (fixed amount) payment.

With the new Stripe Checkout I can generate the HTML Code to build a button that I can include in a website. I'd like to avoid sending people to a website where they have to click that button, but send them straight to the payment form based on the parameters in a URL. Is this possible?

like image 676
Kai Avatar asked May 27 '19 22:05

Kai


3 Answers

Edit: This is now possible with the launch of Payment Links! Check it out here: Stripe Payment Links

This is unfortunately not possible. Stripe.js generates a unique redirect page for each redirectToCheckout call using your publishable key. This ensures that the page is unique to each customer so it can be tracked easier.

You can't really get around sending your customers to a website as even legacy Checkout requires the use of JavaScript to generate the payment form.

like image 161
Paul Asjes Avatar answered Sep 20 '22 22:09

Paul Asjes


You can make an Invoice on stripe.com which will generate an e-mail with link to the payment. Using that, you don't need any webserver.

like image 34
Piaer Avatar answered Sep 22 '22 22:09

Piaer


Yes,

This can be done with a custom script on your end. As mentioned earlier each page has a unique ID used for tracking, therefore it cant be reused.

But with something like a simple PHP script which initiates this payment you can surely use the URL to the php script as a "constant" url to the payment.

The php would and JS would look something like this after having imported the stripe PHP SDK using composer and stripe.js

<?php
$stripecheckout = \Stripe\Checkout\Session::create([
  'success_url' => 'https://success.url',
  'cancel_url' => 'https://cancel.url',
  'payment_method_types' => ['card'],
  'line_items' => [
    [
      'amount' => 100,
      'currency' => 'usd',
      'name' => '1 item',
      'description' => 'This is my item description',
      'quantity' => 1,
    ],
  ]
]);
 ?>

and then this javascript

 <script>
 var stripe = Stripe('pk_test_XXXXXXXXXXXXXXX');
 stripe.redirectToCheckout({
 sessionId: '<?php echo $stripecheckout->id; ?>'
 }).then(function (result) {
   // If `redirectToCheckout` fails due to a browser or network
   // error, display the localized error message to your customer
   // using `result.error.message`.
 });
 </script>

This will require some customization and error handling from your end, but in my opinion would be the best solution

like image 20
Oscar Sortland Kolsrud Avatar answered Sep 19 '22 22:09

Oscar Sortland Kolsrud