- The code is supplied as-is and is not maintained by VTEX.
- The maintanance and development of new functionalities is responsability of whomever installs it on their store.
- This code is not property of VTEX.
This code is provided as is, use it and customize it at your risk and convenience.
The objective of this app is to manage the cancelation of Paypal incomplete orders with a custom frequency.
- Use the following VTEX CLI command to install the service in your store
vtex install vtex.paypal-utils
-
Setup a cron job to request the activation of the app with a suggested frequency of 5 to 10 mins, depending on your store's order volume.
-
URL:
https://{{account}}.myvtex.com/_v/payPal2?cancel=true
-
Frequency:
*/10****
-
The manifest.json file has specific access policies, in this specific case, we have the outbound for the vtex portal account.
For more on the manifest configuration please click here
The middlewares for this service are PayPal2.ts and PayPalOrders.ts
-
This middleware has the following functions:
-
This function will iterate over all the payments on your VTEX store and filter the paypal transactions with status authorizing within a time period.
For more on the API, click here
-
This function will iterate over the transactionList given by listTransactions and will filter all the paypal paymentInteractions in order to get the id and authToken
For more on the API, click here
-
This function will iterate over the interactions and impact Paypal's API sending the TransactionId and value of the order to cancel.
For more on the API, click here
-
-
This middleware has the following functions:
-
This function will iterate over all the orders given to it which are paid with paypal in which the incompleteOrders status is true and within a time period.
For more on the API, click here
-
This function will iterate over all the payments on your VTEX store and filter the paypal transactions with status authorizing within a time period.
For more on the API, click here
-
This function will list the details of all the orders given to it based on the orderId given and the vtex authToken.
For more on the API, click here
-
This function has three steps,
- it will first push to the transactionsList array all the orders with their details.
- Then, it will map transactionsList in order to loop over the specific interactions of the order to check if it's canceled or not and push it to the i array.
- Then it will check if the order is in fact waiting to be canceled based on the messege.
For more on the API, click here
-
This function will cancel all the interactions given to it by passing the cancelation interaction to the gateway give.
For more on the API, click here
-
The client for this service is PayPalUtils.ts
-
This client will be explained in parts:
-
Imports from the @vtex/api and routes which will be used to access the payments, orders and transactions APIs which we will use with the functions in our middlewares.
-
PayPalUtils Class will extend Janus Client to access the core commerce apis in vtex io, in order to use the listOrders, orderDetail and paymentInteractions functions in our middlewares and send the routes the orders and transactions information via API.
For more on the API, click here
-
GatewayClient extends ExternalClient in order to use the specified client to cancel the transaction.
For more on the API, click here
-
AdminTransactions extends ExternalClient in order get the transactions of the specified account.
For more on the API, click here
-
This file will export the service object and will import necessary methods to use that are in vtex API, middlewares and clients.
These are utilitarian methods used through out the service, please read through them carefully
- authToken.js
- cachedContext.ts
- seller.js
- statusError.ts
- tracing.js
- Rodrigo Olivera