Skip to content

Commit 37e76b7

Browse files
committed
feat(paypal): Setup PayPal (Plus) payment integration app
1 parent 9785982 commit 37e76b7

File tree

20 files changed

+1119
-76
lines changed

20 files changed

+1119
-76
lines changed

packages/apps/paypal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please refer to GitHub [repository releases](https://github.com/ecomplus/cloud-commerce/releases) or monorepo unified [CHANGELOG.md](https://github.com/ecomplus/cloud-commerce/blob/main/CHANGELOG.md).

packages/apps/paypal/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# `@cloudcommerce/app-paypal`
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(function paypalOnload() {
2+
window._pppContinue = new Promise((resolve, reject) => {
3+
// https://developer.paypal.com
4+
// /docs/integration/paypal-plus/mexico-brazil/integrate-a-payment-selection-page/
5+
const pppParams = {
6+
approvalUrl: window._paypalApprovalUrl,
7+
disallowRememberedCards: Boolean(window._paypalDisallowRemembered),
8+
placeholder: 'ppplus',
9+
mode: window._paypalEnv,
10+
disableContinue: 'pppContinue',
11+
enableContinue: 'pppContinue',
12+
onContinue(rememberedCards, payerId, paymentId) {
13+
resolve({
14+
credit_card: {
15+
token: rememberedCards || '',
16+
},
17+
intermediator_buyer_id: payerId,
18+
open_payment_id: window._paypalPaymentId
19+
+ '/' + paymentId
20+
+ '/' + window._paypalInvoiceNumber,
21+
});
22+
},
23+
onError(err) {
24+
reject(err);
25+
},
26+
onLoad() {
27+
const $loading = document.getElementById('pppLoading');
28+
if ($loading) {
29+
$loading.remove();
30+
}
31+
},
32+
};
33+
34+
if (window.storefrontApp) {
35+
const customer = window.storefrontApp.customer;
36+
if (customer) {
37+
pppParams.payerEmail = customer.main_email;
38+
pppParams.payerTaxId = customer.doc_number;
39+
pppParams.payerTaxIdType = customer.registry_type === 'j' ? 'BR_CNPJ' : 'BR_CPF';
40+
pppParams.country = customer.doc_country || 'BR';
41+
if (pppParams.country === 'BR') {
42+
pppParams.language = 'pt_BR';
43+
}
44+
if (customer.name && customer.name.given_name) {
45+
pppParams.payerFirstName = customer.name.given_name;
46+
if (customer.name.middle_name && customer.name.family_name) {
47+
pppParams.payerLastName = customer.name.middle_name + ' ' + customer.name.family_name;
48+
} else if (customer.name.middle_name || customer.name.family_name) {
49+
pppParams.payerLastName = customer.name.middle_name || customer.name.family_name;
50+
}
51+
}
52+
if (Array.isArray(customer.phones) && customer.phones[0]) {
53+
pppParams.payerPhone = customer.phones[0].number.toString();
54+
}
55+
}
56+
}
57+
58+
window._pppApp = window.PAYPAL.apps.PPP(pppParams);
59+
});
60+
}());

packages/apps/paypal/events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/paypal-events';

packages/apps/paypal/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@cloudcommerce/app-paypal",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"description": "e-com.plus Cloud Commerce app to integrate PayPal Plus",
6+
"main": "lib/paypal.js",
7+
"exports": {
8+
".": "./lib/paypal.js",
9+
"./events": "./lib/paypal-events.js"
10+
},
11+
"files": [
12+
"/lib",
13+
"/lib-mjs",
14+
"/assets",
15+
"/types",
16+
"/*.{js,mjs,ts}"
17+
],
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
21+
"directory": "packages/apps/paypal"
22+
},
23+
"author": "E-Com Club Softwares para E-commerce <[email protected]>",
24+
"license": "MIT",
25+
"bugs": {
26+
"url": "https://github.com/ecomplus/cloud-commerce/issues"
27+
},
28+
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/paypal#readme",
29+
"scripts": {
30+
"build": "bash scripts/build.sh"
31+
},
32+
"dependencies": {
33+
"@cloudcommerce/api": "workspace:*",
34+
"@cloudcommerce/firebase": "workspace:*",
35+
"@ecomplus/utils": "1.5.0-rc.6",
36+
"axios": "^1.10.0",
37+
"firebase-admin": "^13.4.0",
38+
"firebase-functions": "^6.3.2"
39+
},
40+
"devDependencies": {
41+
"@cloudcommerce/types": "workspace:*"
42+
}
43+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
node ../../../scripts/assets-minification.mjs
4+
bash ../../../scripts/build-lib.sh

packages/apps/paypal/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line import/prefer-default-export
2+
export * from './paypal';

0 commit comments

Comments
 (0)