Reputation: 57
I am using Woocommerce for backend and react js for the front end. Since woocommerce is supported with apis, I am trying to integrate PayPal for payment gateway. Default WordPress themes work with woocommerce are making the payment in the following flow.
My question is How can I achieve this process with REST API.
Is it best to use client-side integration or server-side integration? If using client-side integration, will there be any vulnerability? How can I confirm that the user paid the value of the cart?
Upvotes: 3
Views: 1504
Reputation: 129
Both Woocommerce and PayPal are having their own api resources.
Using their API documentation we can achieve the restful API implementation which can communicate both with woocommerce for order/shop management as well as the paypal for payment management
API request will always be initiated from the client side so we can start implementing from the client side but the main thing is that the endpoint shouldn't actually point either paypal or wooocommerce real endpoints, instead we should implement the API related works in the server side with our own endpoints. For example, for creating order in woocommerce the actual endpoint is
curl -X POST https://<store_domain>/wp-json/wc/v3/orders \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{payload}'
We shouldn't use this directly instead we can do like,
https://api.<store_domain>.com/create_order/
with some header authentication and then the server,
api.<store_domain>.com
should call actual woocommerce store,
https://<store_domain>/wp-json/wc/v3/orders
endpoint same way for PayPal request too so that the payload that has been used for the API resources in both woocommerce and paypal will not be visible to the end-user.
In a similar way the response from the paypal should be redirected to
api.<store_domain>.com
after verifying whether the transaction was successful or not and then using the api response we can handle it in react js by this way we can ensure the security! For more information regarding handling the response from the endcustomer please refer the URL.
Upvotes: 2