@social-mail/social-mail-web-server 1.8.65 → 1.8.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/seed/ui/seed-ui.js +2 -2
- package/dist/server/services/store/gateways/paypal.d.ts +14 -0
- package/dist/server/services/store/gateways/paypal.d.ts.map +1 -0
- package/dist/server/services/store/gateways/paypal.js +82 -0
- package/dist/server/services/store/gateways/paypal.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/server/seed/ui/seed-ui.ts +2 -2
- package/src/server/services/store/gateways/paypal.tsx +87 -0
package/package.json
CHANGED
|
@@ -5,13 +5,13 @@ export default async function seedUI(config: DBConfig) {
|
|
|
5
5
|
await config.saveVersion(UIPackageConfig, {
|
|
6
6
|
package: "@social-mail/social-mail-client",
|
|
7
7
|
view: "dist/web/AppIndex",
|
|
8
|
-
version: "1.8.
|
|
8
|
+
version: "1.8.237"
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
await config.saveVersion(WebComponentsPackageConfig, {
|
|
12
12
|
package: "@social-mail/web-components",
|
|
13
13
|
view: "dist/index.js",
|
|
14
|
-
version: "1.0.
|
|
14
|
+
version: "1.0.337"
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
await config.saveVersion(FAFreePackageConfig, {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Inject from "@entity-access/entity-access/dist/di/di.js";
|
|
2
|
+
import { StoreJournal } from "../../../model/entities/StoreJournal.js";
|
|
3
|
+
import StorePaymentAttempt from "../../../model/entities/StorePaymentAttempt.js";
|
|
4
|
+
import StorePaymentGateway from "../../../model/entities/StorePaymentGateway.js";
|
|
5
|
+
import EncryptionService from "../../encryption/EncryptionService.js";
|
|
6
|
+
import LedgerPaymentGateway from "../LedgerPaymentGateway.js";
|
|
7
|
+
import FetchBuilder from "@web-atoms/fetch-builder";
|
|
8
|
+
import SocialMailContext from "../../../model/SocialMailContext.js";
|
|
9
|
+
import Content from "@entity-access/server-pages/dist/Content.js";
|
|
10
|
+
import HtmlDocument from "@entity-access/server-pages/dist/html/HtmlDocument.js";
|
|
11
|
+
import XNode from "@entity-access/server-pages/dist/html/XNode.js";
|
|
12
|
+
|
|
13
|
+
export default class extends LedgerPaymentGateway {
|
|
14
|
+
|
|
15
|
+
@Inject
|
|
16
|
+
ecs: EncryptionService;
|
|
17
|
+
|
|
18
|
+
@Inject
|
|
19
|
+
db: SocialMailContext;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async createPayment(host: string, gateway: StorePaymentGateway, order: StoreJournal, pa: StorePaymentAttempt) {
|
|
23
|
+
|
|
24
|
+
const secret = this.ecs.secure.decrypt(gateway.encryptedSecret);
|
|
25
|
+
|
|
26
|
+
const pID = this.ecs.general.encrypt(pa.attemptID.toString());
|
|
27
|
+
|
|
28
|
+
const items = await this.db.storeJournalLineItems.where(order, (p) => (x) => x.journalID === p.journalID)
|
|
29
|
+
.include((x) => x.itemPrice.storeItem)
|
|
30
|
+
.toArray();
|
|
31
|
+
|
|
32
|
+
const { emailAddress: { emailAddress: email_address}} = await this.db.storeAccountEmails
|
|
33
|
+
.where(order, (p) => (x) => x.accountID === p.buyerID)
|
|
34
|
+
.include((x) => x.emailAddress)
|
|
35
|
+
.first();
|
|
36
|
+
|
|
37
|
+
const pr = await FetchBuilder.url("https://api-m.paypal.com")
|
|
38
|
+
.post("/v2/checkout/orders")
|
|
39
|
+
.header("Authorization", `Bearer ${Buffer.from(`${gateway.clientID}:${secret}`).toString("base64")}`)
|
|
40
|
+
.jsonBody({
|
|
41
|
+
intent: "CAPTURE",
|
|
42
|
+
payment_source: {
|
|
43
|
+
paypal: {
|
|
44
|
+
experience_context: {
|
|
45
|
+
payment_method_preference: "IMMEDIATE_PAYMENT_REQUIRED",
|
|
46
|
+
payment_method_selected: "PAYPAL",
|
|
47
|
+
brand_name: host,
|
|
48
|
+
landing_page: "LOGIN",
|
|
49
|
+
user_action: "PAY_NOW",
|
|
50
|
+
return_url: `https://${host}/store/checkout-callback/${pID}`,
|
|
51
|
+
cancel_url: `https://${host}/store/checkout-callback/${pID}`,
|
|
52
|
+
},
|
|
53
|
+
email_address
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
purchase_units: [{
|
|
57
|
+
invoice_id: `${order.journalID}`,
|
|
58
|
+
reference_id: `${order.journalID}`,
|
|
59
|
+
amount: order.total,
|
|
60
|
+
items: items.map((x) => ({
|
|
61
|
+
name: x.item.name,
|
|
62
|
+
quantity: x.quantity || 1,
|
|
63
|
+
currency: x.itemPrice.currency,
|
|
64
|
+
unit_amount: (Number(x.total) / x.quantity).toFixed(2),
|
|
65
|
+
|
|
66
|
+
}))
|
|
67
|
+
}]
|
|
68
|
+
}).asJson();
|
|
69
|
+
|
|
70
|
+
const link = pr.links.find((x) => x.rel === "payer-action");
|
|
71
|
+
|
|
72
|
+
return Content.html(<HtmlDocument>
|
|
73
|
+
<head>
|
|
74
|
+
<title>Preparing Paypal Order</title>
|
|
75
|
+
</head>
|
|
76
|
+
<body>
|
|
77
|
+
<script>
|
|
78
|
+
location.href = {JSON.stringify(link.href)};
|
|
79
|
+
</script>
|
|
80
|
+
</body>
|
|
81
|
+
</HtmlDocument>);
|
|
82
|
+
}
|
|
83
|
+
isSuccessful(pa: StorePaymentAttempt) {
|
|
84
|
+
throw new Error("Method not implemented.");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|