1.0.5 • Published 2 years ago

stripeeasyintegration v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Getting started

We are using stripe ( version : 8.179.0 ) npm package. And we are using this only for stripe custom flow or stripe card payments. This is the most compatible with the React js and Node js.

Payment flow

In 90% of the cases the payment flow will be the same not just only for stripe but for all of the payment gateways which are in the world.

Each and every payment gateway will have these three things Create Order API, Verify Order API and a Webhook.

Create Order API => This is basically used to create the order or initiating an order from the front end. Front end will call this api with some payload related to that payment (Payload can be the data related to that purchase).

Verify Order API => After sucessful payment from the front end to the payment gateway (In our case its stripe) front end will receive some keys from that payment gateway which we can use to verify that order. Front end will call this Verify Order API in the backend with this payload and backend will verify the payment by calling methods from that paymnet gateway with the payload which we got from the front end. And accordingly change the status of that payment into the database.

Webhook => In all of the payment gateways we have this webhook. Webhook is just an api route which is used by that payment gateways. Assume that in the web we created an order and our payment got sucessful but suddenly we have refreshed our page without calling the verify order api which changes the payment status in the backend. Now the webhook comes into the practice. Webhook is an api route which is hit by that payment gateway with some payload whenever a payment is made and changes the status of that payment in our backend. Webhoooks are generally slow and are server to server calls. So we have to rely on that Verify Order Api to get the payment status to do changes in the front end accordingly. We have to add a webhook route into the payment gateway dashboard for its functioning.

setStripeKeys method

This method is used to set the stirpe private keys in the backend. Before implementation stripe payment gateway we have to initialize keys with this method in the server.js or app.js file.

yourVariable.setStripeKeys(key) // like this we can pass our private key into it and initialize this.

createOrderStripe method

This method is used to create an intent by calling stripe methods. In this mehtod we take 4 things passed in an object as an argument.

  1. amount => This will be in the smallest single unit possible in that particular currency.
  2. currency => This is the currency string which we have to pass in this method.
  3. callbackFn => This is a callback function written by you where all of the database queries are happening where we are saving the payload , status of that payment into the database.
  4. payload => This is the payload which we are going to save into the database. In this payload we will add two keys. "status" key which tells us the payment status and the "paymentMethod" key which tells us through which payment gateway the payment is made.

And, at the end this method will return four things.

  1. clientSecret => This is required in the front end to do any kind of stripe payment.
  2. orderId => This is also required in the front end to verify the payment.
  3. paymentIntent => This is the whole object we get when we calls the stripe methods. If we need any additional data from stripe then we can use this object to get that data.
  4. callbackFnResponse => This is the callback function response which you have passed into it.

NOTE - For currency and amount related reference must go through these links = https://stripe.com/docs/currencies and https://stripe.com/docs/api/payment_intents/create

verifyOrderStripe

This method is used to verify an order by calling stripe methods. In this mehtod we take 2 things passed in an object as an argument.

  1. orderId => This order id is used to get the status of the payment by calling stripe methods.
  2. callbackFn => This is a callback function written by you where all of the database queries are happening where we are saving the payload , status of that payment into the database.
  3. payload => This is the payload which we are going to save into the database. In this payload we will be adding the status of this particular payment and this status needs to be saved into the database.

And, at the end this method will return three things.

  1. status => This will be telling you the status of the payment and accordingly we can send data to the front end.
  2. paymentIntent => This is the whole object we get when we calls the stripe methods. If we need any additional data from stripe then we can use this object to get that data.
  3. callbackFnResponse => This is the callback function response which you have passed into it.

webhookStripe

This method is used to verify an order by calling stripe methods. If the front end fails to call the verify order api then this will come into the practice and change the state of the payment into the database. Each and every time the payment is made into the front end this webhook will be hit by the stripe with some payload in it. So it will be a post api.

  1. request => When stripe will hit this endpoint it will give us the request object. We have to pass the whole request object received from the stripe into this webhookStripe method.
  2. callbackFn => This is the function which is required. It will be executed after verifying order and change the payment status into the database. The response is totally depends on the callback funtion which is passed into it.
  3. payload => If we wants to change the status as well as some of the other things into the db then we can use this payload.
  4. striptEndpointSecret => This we will get from the stripe dashboard.

And, at the end this method will return three things.

  1. status => This will be telling you the status of the payment.
  2. callbackFnResponse => This is the callback function response which you have passed into it.
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago