Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-02-03 20:01:07

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 196
Website

Stripe Payments API integration

Robin Gibson Gallery currently uses Stripe Prebuilt Checkout Page for selling artworks online.

They want to use Stripe API to allow for online subscription payments as well (eg. 4 payments of $150).

I’m looking for someone to set up Stripe as described in their documentation (every time I’ve tried this setting this up myself on my Mac I’m blocked by endless walls of minutiae, techniques that I suspect are obvious to others ;-)

robingibson.net runs on TXP v4.8.1

Offline

#2 2021-02-07 19:37:52

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 196
Website

Re: Stripe Payments API integration

No Takers?

🧐

Can anyone suggest a reputable php developer who could help out?

Thanks

Offline

#3 2021-02-07 23:06:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,089
Website

Re: Stripe Payments API integration

I’m not entirely sure I understand how they plan to take Stripe subscription payments yet.

Stripe seem to imply from the docs, that you either use the command line tools to set up subscriptions or do it via some ‘dashboard’ – whatever that is. I notice that clicking ‘buy’ on the site takes you to checkout.stripe.com and it shows a copy of whatever is in the basket, so I presume all the products are loaded into Stripe’s database somehow and it just needs configuring to accept subscriptions?

Further question: does Txp need to monitor for invoice.paid events to check that each payment has gone through and, if it fails, what action needs to be taken? If you’re buying a piece of art and pledge to pay 4 instalments, presumably the piece is delivered after the first payment is made, so what’s to stop the customer cancelling the subscription after one payment? Or is it only delivered after the final payment is accepted? In which case, what action needs to take place on successful completion of the Nth payment?

I’ll take a look for sure if you can give me some access info and details of scope. By all means drop me an email and we can go from there.

Last edited by Bloke (2021-02-07 23:07:30)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2021-02-08 01:56:59

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 196
Website

Re: Stripe Payments API integration

Thanks Stef

I’ll send you an email…

Offline

#5 2021-02-08 08:19:46

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,387
Website

Re: Stripe Payments API integration

Hi,

I did it for a client few years ago, i got a head ache for making it working but it worked (it was a one time payment and subscription) but that take me a lot of time to understund how it works, i will try to post the php code i used for that, that should help you.

You need to download the stripe access lib from github and modify the config.php with your own api key.

Cheers.

Below to make a usbscription:

<txp:php>
			require('/home/stripe/config.php');

			if (isset($_POST['stripeToken'])){

				$token  = $_POST['stripeToken'];

				$qui = cbe_frontauth_whois(array());
				$emailqui = cbe_frontauth_whois(array("type" =>"email"));

				$mont = variable(array("name"=>"mont100"));

				try
				{
					$customer = \Stripe\Customer::create(array(
						'email' => $_POST['stripeEmail'],
						'source'  => $_POST['stripeToken'],
						'plan' => 'MyPlan',
						'tax_percent' => 20.0
					));

					$resul = $customer->jsonSerialize();
					variable(array(name=>"idsub",value=>$resul[subscriptions][data][0][id]));
					/* echo "<h2>Abonnement N° ".$resul[subscriptions][data][0][id]."</h2>"; */

					$startabon = date('d/m/Y', $resul[subscriptions][data][0][created]);
					variable(array(name=>"startabon",value => "$startabon"));

				}
				catch(Exception $e)
				{

					error_log("unable to sign up customer:" . $_POST['stripeEmail'].
						", error:" . $e->getMessage());

					$err1= $e->getMessage();
				}

				if (!isset($err1)){

					echo '<div class="row"><div class="col-sm-12"><p style="text-align:left;color:green;margin:10px auto;"><b>Subscription succeeded</b></p></div></div>';

				} else {

					echo "<p style='color:red;'>Error Type :</p>";
					var_dump($err1);
				}
			}
		</txp:php>

Below the code to cancel a subscriptions :

<txp:php>
			require('/home/stripe/config.php');

			$subs = variable(array("name"=>"numabonnement"));

				try
				{
					$subscription = \Stripe\Subscription::retrieve($subs);

					$resull = $subscription->jsonSerialize();
					variable(array(name=>"resull",value=>$resull[id]));

					$subscription->cancel();
				}
				catch(Exception $e)
				{
					$err1= $e->getMessage();
				}

				if (!isset($err1)){

					echo '<p style="text-align:left;color:green;margin:10px auto;"><b>Subscription canceled</b></p>';


				} else {

					echo "<p style='color:red;'>Error</p>";
					var_dump($err1);
				}

		</txp:php>

If you wonder what is config.php :

<?php
require_once('/home/stripe/init.php');
$stripe = array(
  "secret_key"      => "",
  "publishable_key" => ""
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>

p.

Offline

#6 2021-02-08 18:05:20

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 196
Website

Re: Stripe Payments API integration

Dragondz wrote #328609:

I did it for a client few years ago, i got a head ache for making it working but it worked (it was a one time payment and subscription) but that take me a lot of time to understund how it works, i will try to post the php code i used for that, that should help you.

Thank you!

Offline

#7 2021-02-09 07:46:01

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,387
Website

Re: Stripe Payments API integration

Hi

The code is made in 2017 but the website that use it is still online and it is working then it should works, hope that can help you.

I forgot to post the code that generate the stripe form :

<form method="POST">
				<script
					src="https://checkout.stripe.com/checkout.js" class="stripe-button"
					data-key="YourAPIkey"
					data-amount='<txp:variable name="mont100"/>'
					data-name="Subscribe"
					data-currency="eur"
					data-description='<txp:variable name="mont00"/>€ + 20% TVA'
					data-image="ImgURL"
					data-locale="fr"
					data-billingAddress="true"
					data-label="SUBSCRIPTION"
					data-zip-code="true">
				</script>
			</form>

Offline

Board footer

Powered by FluxBB