Jump to content

Stripe payment links in pw - easy way


angelo, italy
 Share

Recommended Posts

Hi,

I want to share an easy way to use Stripe Payment Links in processwire website:

1) Upload folder 'stripe-php' in site/templates (attached)

2) Upload file init.php in site/templates (attached)

3) Use variables in template 'product':

$xxx = $page->prezzo_interno;
$session->set(prod, "$page->title"); 
$session->set(price, $xxx);

4) Insert a form in the template 'product'

5) Copy ApiKey in Stripe Account

5) Create a template 'checkout' and copy Apikey

<?php 

//include './stripe-php/init.php';
include 'init.php';

//require 'vendor/autoload.php';


Stripe\Stripe::setApiKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxx');



header('Content-Type: application/json');

$YOUR_DOMAIN = 'https://www.dominio.it/';


$checkout_session = \Stripe\Checkout\Session::create([
  'shipping_address_collection' => [
    'allowed_countries' => ['IT'],
  ],
  'shipping_options' => [
    [
      'shipping_rate_data' => [
        'type' => 'fixed_amount',
        'fixed_amount' => [
          'amount' =>
          500,
          'currency' => 'eur',
        ],
        'display_name' => 'Standard',
        // Delivers between 5-7 business days
        'delivery_estimate' => [
          'minimum' => [
            'unit' => 'business_day',
            'value' => 5,
          ],
          'maximum' => [
            'unit' => 'business_day',
            'value' => 7,
          ],
        ]
      ]
    ],
    [
      'shipping_rate_data' => [
        'type' => 'fixed_amount',
        'fixed_amount' => [
          'amount' => 800,
          'currency' => 'eur',
        ],
        'display_name' => 'Celere',
        // Delivers in exactly 1 business day
        'delivery_estimate' => [
          'minimum' => [
            'unit' => 'business_day',
            'value' => 1,
          ],
          'maximum' => [
            'unit' => 'business_day',
            'value' => 3,
          ],
        ]
      ]
    ],
  ],
  'line_items' => [[
    # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
 
  'name' =>  $session->get(prod),
     'amount' => $session->get(price),
    'currency' => 'eur',
    'quantity' => 1
      
  ]],
  'mode' => 'payment',
  'discounts' => [[
    'coupon' => '1',
  ]],
  'success_url' => $YOUR_DOMAIN . 'grazie/',
  'cancel_url' => $YOUR_DOMAIN . 'pagamento-rifiutato/',
]);

header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);

.. and that's it!

I hope it could be useful for everybody here!

Bye

Archivio.zip

  • Like 4
Link to comment
Share on other sites

  • 3 weeks later...

Hi Angelo, thanks for sharing this.

I would like to test it, but I need two clarification if it's possible (from you o from who already tested it):

  • Point 3) Use variables in template 'product':

Does $page->title need quotation marks or not? If yes, are you sure to use without concatenation syntax? eg.

'"' . $page->title . '"'
  • Point 4) Insert a form in the template 'product':  what "form" stands for?

It's a specific html form with buying data or something else?

 

...and last, but not least: please, can you specify which ApiKey to use?

Many thanks in advance.

 

 

Link to comment
Share on other sites

2 hours ago, Cybermano said:

...

I would like to test it, but I need two clarification if it's possible

...

Maybe I've found my way playing a bit.

For other newbies like me, I think the pointed requests are:

  1. setApikey=> sk_key
  2. according to pw syntax $session->set('key', 'value') => $session->set('prod', $page->title)
  3. form stands for an html <form></form> with options to get info such as shipping methods, product quantity, discount codes, coupons and so on... to calculate the final amount

 

I think Stripe Payment Links work greatly with a simple <a> tag, such as

<a title="Stripe checkout for This Product" href="https://buy.stripe.com/my_productlink" target="_blank">This Product</a>

in PW we could have a template with a field for the link and output the same as

<a title="Stripe checkout for <?= $page->title ?>" href="<?= $page->stripe_payment_link ?>" target="_blank"><?= $page->title ?></a>

and in this case we could also publish into some socials from PW like fb, telegram, and so on.

 

But I think I've missed something important from your post:

How does a Stripe Pyment Link interact with the above php checkout?

Link to comment
Share on other sites

  • 2 months later...

Grazie @angelo, italy

This saved my life today. Would be great to develop this integration as a Processwire module.

@Cybermano to interact with the checkout page you just need a post form with the action to the checkout page. Ex:

<form action='<?php echo $pages->get('template=checkout')->url; ?>' method='POST' >
    <button type='submit' id='checkout-button' >Pay with Credit Card</button>
</form>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...