Skip to content

Jose-IFR/testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 

Repository files navigation

Paypal Service utils

vtex-version maintained-status

⚠️ DISCLAIMER ⚠️

  • 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.

Table of Contents

  1. About The Project
  2. Getting Started
  3. How to
  4. Acknowledgments

About The Project

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.

Service Example Architecture

(back to top)

Getting Started

App installation

  • Use the following VTEX CLI command to install the service in your store
    vtex install vtex.paypal-utils

Usage

  1. 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****

⚠️ If you don't have a dedicated server to run your cron jobs, then we suggest using Google Cloud Scheduler, however you can use the service of your choice.

Google Scheduler Screen

(back to top)

How does this service work?

manifest.json

The manifest.json file has specific access policies, in this specific case, we have the outbound for the vtex portal account.

drawing

For more on the manifest configuration please click here

(back to top)

Middlewares

The middlewares for this service are PayPal2.ts and PayPalOrders.ts

  • PayPal2.ts

    This middleware has the following functions:
    • listTransactions

      This function will iterate over all the payments on your VTEX store and filter the paypal transactions with status authorizing within a time period.

      drawing

      For more on the API, click here

    • interactions

      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

      drawing

      For more on the API, click here

    • cancel

      This function will iterate over the interactions and impact Paypal's API sending the TransactionId and value of the order to cancel.

      drawing

      For more on the API, click here

(back to top)

  • PayPalOrders.ts

    This middleware has the following functions:

    • listOrders

      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.

      drawing

      For more on the API, click here

    • listTransactions

      This function will iterate over all the payments on your VTEX store and filter the paypal transactions with status authorizing within a time period.

      drawing

      For more on the API, click here

    • listOrdersDetail

      This function will list the details of all the orders given to it based on the orderId given and the vtex authToken.

      drawing

      For more on the API, click here

    • paymentInteractions

      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.
      drawing

      For more on the API, click here

    • cancelTransaction

      This function will cancel all the interactions given to it by passing the cancelation interaction to the gateway give.

      drawing

      For more on the API, click here

Clients

The client for this service is PayPalUtils.ts

  • 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.

      drawing

    • 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.

      drawing

      For more on the API, click here

    • GatewayClient extends ExternalClient in order to use the specified client to cancel the transaction.

      drawing

      For more on the API, click here

    • AdminTransactions extends ExternalClient in order get the transactions of the specified account.

      drawing

      For more on the API, click here

index.ts

This file will export the service object and will import necessary methods to use that are in vtex API, middlewares and clients.

utils

These are utilitarian methods used through out the service, please read through them carefully

  • authToken.js
  • cachedContext.ts
  • seller.js
  • statusError.ts
  • tracing.js

(back to top)

Acknowledgments

  • Rodrigo Olivera

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published