/app-paypal

E-Com Plus app to integrate PayPal checkout

Primary LanguageJavaScriptMIT LicenseMIT

App PayPal

License MIT

E-Com Plus app to integrate PayPal SPB & Plus

CHANGELOG

About

This application will:

  1. Integrate PayPal business account;
  2. Add payment methods and create transactions with Modules API (List payments & Create transaction);
  3. Receive PayPal Webhooks to update transaction status on created orders;

App hidden_data will store PayPal App credentials, data will store discount, installments and custom PayPal SPB/Plus options.

data/hidden_data expected object model is defined (JSON Schema) on app admin_settings.

It's based on E-Com Plus Express App Boilerplate, application installation and authentication was kept as is with original endpoints from boilerplate source:

List payments module endpoint

Additional endpoint was created to handle list_payments (/ecom/modules/list-payments) module, it receives requests from Modules API on stores with this app installed.

It'll receive POST with body like:

{
  "params": {
    "items": [
      {
        "name": "Monitor Gamer Asus ROG Swift LED 24\" Widescreen FHD PG248Q",
        "sku": "HUJ1471",
        "price": 2995.36,
        "quantity": 1,
        "currency_id": "BRL",
        "currency_symbol": "R$",
        "product_id": "5c705802c626be23430d5053",
        "final_price": 2995.36
      }
    ],
    "amount": {
      "freight": 50.39,
      "discount": 0,
      "total": 3045.75,
      "subtotal": 2995.36
    },
    "currency_id": "BRL",
    "currency_symbol": "R$"
  },
  "application": {
    "hidden_data": {
      "paypal_client_id": "1234",
      "paypal_secret": "123456"
    },
    "data": {
      "enable_paypal_plus": true
    }
  }
}

Then:

  1. Check for SPB (new version), checkout.js and/or PayPal Plus enabled;

  2. Setup payment methods clients (onload expressions) to run on Storefront App;

  3. Check/apply discount option by payment method;

  4. Create Payment for PayPal Plus or checkout.js if used;

  5. Return response with configured payment methods objects;

Full params object reference from Modules API docs.

Full data/hidden_data object referece on application.json admin_settings.

Full response object reference from Modules API docs.

Create transaction module endpoint

Additional endpoint was created to handle create_transaction (/ecom/modules/create-transaction) module, it receives requests from Modules API to:

  1. Executed PayPal Payment or read created PayPal Order (new SPB);
  2. Save PayPal Payment/Order ID associated to E-Com Plus Order ID for status synchronization (SQLite3);
  3. Send response to confirm/cancel E-Com Plus order;

PayPal Webhooks endpoint

Custom endpoint to handle PayPal Webhooks (/paypal/webhook):

  1. Validate and read PayPal Webhook event;
  2. Read local database (SQLite3) to match Payment/Order ID of respective even (saved on create transaction);
  3. Check new transaction status and parse to PayPal enum to E-Com Plus enum;
  4. Update E-Com Plus order adding new payment_history with current status;

Environment variables sample

Variable Value
LOGGER_OUTPUT ~/app/log/logger.out
LOGGER_ERRORS ~/app/log/logger.err
LOGGER_FATAL_ERRORS ~/app/log/_stderr
PORT 3000
APP_NAME PayPal
APP_BASE_URI https://paypal.ecomplus.biz
DB_PATH ~/app/db.sqlite
ECOM_AUTH_DB ~/app/db.sqlite
ECOM_AUTH_UPDATE enabled
DAEMON_SERVICES true
PAYPAL_PARTNER_ID EcomPartnerId

Production server

Published at https://paypal.ecomplus.biz

Continuous deployment

When new version is production ready, create a new release (or npm run release) to run automatic deploy from master branch and (re)publish the app.