Set up a custom Stripe payment flow
This article describes an older way to integrate with Stripe, it still works, but we recommend the new way, using Stripe checkout. This is documented in our API docs which you can access at via your Storeganise login at {{businesscode}}.storeganise.com/api/docs/user/billing/stripe#user_billing_stripe.POST_session
Overview
The way we recommend setting up Stripe for a customer is as below:
- Create a User account for the customer via the Storeganise API
- Follow the instructions here to capture the customer's payment details using the Stripe Web UI, and connect the card to the Storeganise user account.
- Create the order; when the order is completed the invoice date is set for the customer; this tells the system which day of the month to create an invoice and charge the customer's card.
Implementation
1. Show the customer the Stripe Web UI
When configuring Stripe Web you'll need your publishable key, which you can get programmatically via the Storeganise API:
Example request
GET /v1/billing/stripe/settings<br><br>Authorization: Bearer 380afb97ced808
Example response
200 OK { "publishableKey": "pk_test_3g4y2ty4yger..." }
You'll also need to request a payment token before the customer submits their card details:
Example request
POST /v1/billing/stripe/token Authorization: Bearer 380afb97ced808
Example response
200 OK { "id": "seti_1FME3RAXX...", "clientSecret": "seti_1FME3RAXX..._secret_FrxzN..." }
2. Submit the Stripe form
Then you're able to call Stripe Web's handleCardSetup()/confirmCardSetup()
with the token.secretToken
obtained previously to save the card.
See the Stripe Web documentation for details:
- https://stripe.com/docs/payments/cards/saving-cards-without-payment#submit-card-details
- https://stripe.com/docs/stripe-js
- https://stripe.com/docs/stripe-js/reference#stripe-handle-card-setup (more technical)
3. Send back the token id to Storeganise
Finally, send the field token.id
(which is equal to result.setupIntent.id
obtained above in handleCardSetup result) back to Storeganise to confirm the payment method creation.
Example request
POST /v1/billing/stripe/sources
Authorization: Bearer 380afb97ced808 Content-Type: application/json;charset=UTF-8 { "token": "seti_1FME3RAXX..." }
Example response
200 OK
4. Check that the customer has a payment method set up
At this point it's finished, you can get updated userinfo that will confirm that the customer has a payment method set up (see the billingMethod attribute).
Example request
GET /v1/auth/userinfo?include=billingMethod Authorization: Bearer 380afb97ced808
Example response
200 OK { "firstName": "John", "lastName": "Smith", ... "billingMethod": "stripe" }
You can also retrieve the specific payment methods that have been set up:
Example request
GET /v1/billing/stripe/sources Authorization: Bearer 380afb97ced808
Example response
200 OK { "id": "card_44w432gr...", "brand": "Visa", "exp_month": 12, "exp_year": 2019, "last4": "1111", ... } ]