App PayPal
E-Com Plus app to integrate PayPal SPB & Plus
About
This application will:
- Integrate PayPal business account;
- Add payment methods and create transactions with Modules API (List payments & Create transaction);
- 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:
/bin/web.js
: Express web server setup;/routes/ecom/auth-callback.js
: Endpoint for E-Com Plus Authentication Callback;
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:
-
Check for SPB (new version), checkout.js and/or PayPal Plus enabled;
-
Setup payment methods clients (onload expressions) to run on Storefront App;
-
Check/apply discount option by payment method;
-
Create Payment for PayPal Plus or checkout.js if used;
-
Return response with configured payment methods objects;
Full
params
object reference from Modules API docs.
Full
data
/hidden_data
object referece on application.jsonadmin_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:
- Executed PayPal Payment or read created PayPal Order (new SPB);
- Save PayPal Payment/Order ID associated to E-Com Plus Order ID for status synchronization (SQLite3);
- Send response to confirm/cancel E-Com Plus order;
PayPal Webhooks endpoint
Custom endpoint to handle PayPal Webhooks
(/paypal/webhook
):
- Validate and read PayPal Webhook event;
- Read local database (SQLite3) to match Payment/Order ID of respective even (saved on create transaction);
- Check new transaction status and parse to PayPal enum to E-Com Plus enum;
- 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.