Skip to content

Commit 9148806

Browse files
committed
Adds readme
1 parent 6ae3037 commit 9148806

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Root Perch Shop Omnipay update
2+
3+
This is an update to the gateways for Perch Shop aimed to make use of the latest Stripe Omnipay gateway so that stripe is able to use 3DS2.
4+
5+
### Note
6+
**I have only tested the Stripe gateways, and as all the Omnipay gateways were upgraded to v3 it is likely they won't work. If anyone can confirm the status of the other gateways it would be much appreciated**
7+
8+
## Changes
9+
10+
### Shop Core
11+
Some core shop files needed to be changed for this to work, though only new methods were used, so any existing shop methods should work as before.
12+
13+
### Gateways
14+
The shop gateway files have not been touched, and only the `PerchShopGateway_stripe_intents.class.php` has been added. However all the Omnipay packages were upgraded from v2 to v3 so it is quite likely that they will no longer work.
15+
16+
### Templates
17+
You'll need to update your page templates and gateway form to make use of the newest gateway. The repo contains some examples for what you would need, but I've outlined the most important below.
18+
19+
##### Payment Form
20+
Probably the biggest change that needs to be done is the change to the gateway payment form. The popup checkout v2 form won't work the Stripe Intents, so we need to create a Payment Method our selves.
21+
22+
We create a new template called `stripe_intents_payment_form.html` in the `templates/shop/gateway` folder
23+
24+
```html
25+
<!-- Regular form, don't want to use perch forms here -->
26+
<form id="stripeForm" action="/checkout" method="post">
27+
<label>
28+
Card details
29+
</label>
30+
<div id="card-element"></div>
31+
<!-- Hidden fields used to send to stripe checkout -->
32+
<input type="hidden" value="<perch:member id="email" escape="true" />" name="email"/>
33+
<input type="hidden" value="<perch:member id="first_name" escape="true" /> <perch:member id="last_name" escape="true" />" name="cardholderName"/>
34+
<!-- Address Fields if passed through -->
35+
<input type="hidden" value="<perch:member id="addressLine1" escape="true" />" name="address"/>
36+
<input type="hidden" value="<perch:member id="city" escape="true" />" name="city"/>
37+
<input type="hidden" value="<perch:member id="postcode" escape="true" />" name="postcode"/>
38+
<!-- ./Address Fields if passed through -->
39+
<input type="hidden" id="paymentMethodID" name="paymentMethodID"/>
40+
<!-- ./Hidden fields used to send to stripe checkout -->
41+
<!-- Regular button as we want to submit with JS -->
42+
<button type="button">Make Payment</button>
43+
</form>
44+
45+
<script src="https://js.stripe.com/v3/"></script>
46+
```
47+
48+
We call this template with the usual way but with the updated gateway `perch_shop_payment_form('stripe_intents')`
49+
50+
By itself the form will do nothing so we need to add the JavaScript to get the payment method from stripe. You [resources/js/perch_stripe_checkout.js](visit resources/js/perch_stripe_checkout.js) for an example.
51+
52+
##### Checkout
53+
Once the form has been submitted we need to take the payment, again this is done in the typical manner and we just need to update the gateway and a few of the arguments
54+
55+
```php
56+
perch_shop_checkout('stripe_intents', [
57+
'return_url' => 'https://yourdomain.com/checkout/complete', // Should probably define these in your config file.
58+
'cancel_url' => 'https://yourdomain.com/checkout/complete',
59+
'payment_method' => perch_post('paymentMethodID'), // Pass the payment method to the gateway
60+
'confirm' => true, // Tell the gateway to confirm the gateway. Require, if you leave this out the intents gateway won't work!
61+
]);
62+
```
63+
##### Complete
64+
Finally on the complete page we need to check if the customer was redirected, and if they were we need to confirm/reject the payment. Here we need to use a newly added method, although it functions very similar to the `perch_shop_checkout` method.
65+
66+
```php
67+
if (PerchUtil::get('payment_intent')) {
68+
69+
$payment_opts = [
70+
'paymentIntentReference' => PerchUtil::get('payment_intent'), // set the reference ID
71+
'returnUrl' => 'http://ecofriendlyshop.local/checkout/complete',
72+
'confirm' => true, // We are confirming the payment so we want this true
73+
];
74+
75+
// New method to confirm the payment. Use the above options and the new intents gateway
76+
perch_shop_confirm_payment('stripe_intents', $payment_opts);
77+
}
78+
```
79+
### Issues
80+
81+
If you find any issues please send them in [here](https://github.com/RootStudio/Root-Perch-Shop-Omnipay-v3/issues)

templates/pages/checkout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* We use the stripe_intents Gateway here, instead of stripe.
1717
*/
1818
perch_shop_checkout('stripe_intents', [
19-
'return_url' => 'https://yourdomain.com/checkout/complete',
19+
'return_url' => 'https://yourdomain.com/checkout/complete', // Should probably define these in your config file.
2020
'cancel_url' => 'https://yourdomain.com/checkout/complete',
21-
'payment_method' => perch_post('paymentMethodID'), //Pass the payment method to the gateway
21+
'payment_method' => perch_post('paymentMethodID'), // Pass the payment method to the gateway
2222
'confirm' => true, // Tell the gateway to confirm the gateway. Require, if you leave this out the intents gateway won't work!
2323
]);
2424
}

0 commit comments

Comments
 (0)