@social-mail/social-mail-web-server 1.8.67 → 1.8.72

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.
Files changed (43) hide show
  1. package/dist/common/globalEnv.d.ts +1 -0
  2. package/dist/common/globalEnv.d.ts.map +1 -1
  3. package/dist/common/globalEnv.js +1 -0
  4. package/dist/common/globalEnv.js.map +1 -1
  5. package/dist/reports/wwwroot/routes/social-mail/reports/api/entity/invoke/[entityName]/[methodName]/index.d.ts +1 -1
  6. package/dist/reports/wwwroot/routes/social-mail/reports/api/entity/invoke/[entityName]/[methodName]/index.d.ts.map +1 -1
  7. package/dist/reports/wwwroot/routes/social-mail/reports/api/entity/invoke/[entityName]/[methodName]/index.js +1 -1
  8. package/dist/reports/wwwroot/routes/social-mail/reports/api/entity/invoke/[entityName]/[methodName]/index.js.map +1 -1
  9. package/dist/server/model/entities/VerificationToken.d.ts +1 -0
  10. package/dist/server/model/entities/VerificationToken.d.ts.map +1 -1
  11. package/dist/server/model/entities/VerificationToken.js +4 -0
  12. package/dist/server/model/entities/VerificationToken.js.map +1 -1
  13. package/dist/server/model/events/VerificationTokenEvents.d.ts +4 -3
  14. package/dist/server/model/events/VerificationTokenEvents.d.ts.map +1 -1
  15. package/dist/server/model/events/VerificationTokenEvents.js +21 -50
  16. package/dist/server/model/events/VerificationTokenEvents.js.map +1 -1
  17. package/dist/server/seed/seed.d.ts.map +1 -1
  18. package/dist/server/seed/seed.js +4 -0
  19. package/dist/server/seed/seed.js.map +1 -1
  20. package/dist/server/seed/ui/seed-ui.js +1 -1
  21. package/dist/server/services/store/gateways/paypal.d.ts +13 -3
  22. package/dist/server/services/store/gateways/paypal.d.ts.map +1 -1
  23. package/dist/server/services/store/gateways/paypal.js +120 -49
  24. package/dist/server/services/store/gateways/paypal.js.map +1 -1
  25. package/dist/server/services/user/email-verification/EmailVerificationService.d.ts +17 -0
  26. package/dist/server/services/user/email-verification/EmailVerificationService.d.ts.map +1 -0
  27. package/dist/server/services/user/email-verification/EmailVerificationService.js +80 -0
  28. package/dist/server/services/user/email-verification/EmailVerificationService.js.map +1 -0
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/dist/wwwroot/routes/social-mail/site/signup/post.d.ts +4 -1
  31. package/dist/wwwroot/routes/social-mail/site/signup/post.d.ts.map +1 -1
  32. package/dist/wwwroot/routes/social-mail/site/signup/post.js +37 -6
  33. package/dist/wwwroot/routes/social-mail/site/signup/post.js.map +1 -1
  34. package/package.json +3 -2
  35. package/src/common/globalEnv.ts +1 -0
  36. package/src/reports/wwwroot/routes/social-mail/reports/api/entity/invoke/[entityName]/[methodName]/index.tsx +1 -1
  37. package/src/server/model/entities/VerificationToken.ts +3 -0
  38. package/src/server/model/events/VerificationTokenEvents.ts +19 -52
  39. package/src/server/seed/seed.ts +4 -0
  40. package/src/server/seed/ui/seed-ui.ts +1 -1
  41. package/src/server/services/store/gateways/paypal.tsx +136 -54
  42. package/src/server/services/user/email-verification/EmailVerificationService.ts +78 -0
  43. package/src/wwwroot/routes/social-mail/site/signup/post.tsx +39 -7
@@ -7,9 +7,10 @@ import EmailAddressService from "../../../../../server/services/EmailAddressServ
7
7
  import CaptchaService from "../../../../../server/services/captcha/CaptchaService.js";
8
8
  import WebSiteContentService from "../../../../../server/services/files/WebSiteContentService.js";
9
9
  import OtpToUserService from "../../../../../server/services/user/otp-to-user/OtpToUserService.js";
10
+ import SessionSecurity from "@entity-access/server-pages/dist/services/SessionSecurity.js";
11
+ import EmailVerificationService from "../../../../../server/services/user/email-verification/EmailVerificationService.js";
10
12
  export interface ISignup {
11
13
  userID: number;
12
- password: string;
13
14
  name: string;
14
15
  phoneNumber: string;
15
16
  emailAddress: string;
@@ -31,6 +32,8 @@ export default class ExternalSignup extends Page {
31
32
  otpService: OtpToUserService;
32
33
  db: SocialMailContext;
33
34
  websiteService: WebSiteContentService;
35
+ sessionSecurity: SessionSecurity;
36
+ evs: EmailVerificationService;
34
37
  run(): Promise<import("@entity-access/server-pages/dist/Content.js").default>;
35
38
  }
36
39
  //# sourceMappingURL=post.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../../../../../src/wwwroot/routes/social-mail/site/signup/post.tsx"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAG5D,OAAO,iBAAiB,MAAM,kDAAkD,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sDAAsD,CAAC;AAC3F,OAAO,iBAAiB,MAAM,2DAA2D,CAAC;AAC1F,OAAO,aAAa,MAAM,iDAAiD,CAAC;AAC5E,OAAO,mBAAmB,MAAM,uDAAuD,CAAC;AACxF,OAAO,cAAc,MAAM,0DAA0D,CAAC;AACtF,OAAO,qBAAqB,MAAM,+DAA+D,CAAC;AAClG,OAAO,gBAAgB,MAAM,qEAAqE,CAAC;AAEnG,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC3C;AAED;;GAEG;AAIH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,IAAI;IAG5C,cAAc,EAAE,cAAc,CAAC;IAG/B,aAAa,EAAE,aAAa,CAAC;IAG7B,mBAAmB,EAAE,mBAAmB,CAAC;IAGz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AAE,cAAc,CAAC;IAG/B,aAAa,EAAE,aAAa,CAAC;IAG7B,mBAAmB,EAAE,mBAAmB,CAAC;IAGzC,UAAU,EAAE,gBAAgB,CAAC;IAG7B,EAAE,EAAE,iBAAiB,CAAC;IAGtB,cAAc,EAAE,qBAAqB,CAAC;IAGtC,eAAe,EAAE,eAAe,CAAC;IAGjC,GAAG,EAAE,wBAAwB,CAAC;IAExB,GAAG;CAyLZ"}
@@ -19,6 +19,8 @@ import EmailAddressService from "../../../../../server/services/EmailAddressServ
19
19
  import CaptchaService from "../../../../../server/services/captcha/CaptchaService.js";
20
20
  import WebSiteContentService from "../../../../../server/services/files/WebSiteContentService.js";
21
21
  import OtpToUserService from "../../../../../server/services/user/otp-to-user/OtpToUserService.js";
22
+ import SessionSecurity from "@entity-access/server-pages/dist/services/SessionSecurity.js";
23
+ import EmailVerificationService from "../../../../../server/services/user/email-verification/EmailVerificationService.js";
22
24
  /**
23
25
  * External Signup is used for signing up for Blog or Store.
24
26
  */
@@ -28,19 +30,40 @@ let ExternalSignup = class ExternalSignup extends Page {
28
30
  db.verifyFilters = false;
29
31
  db.raiseEvents = false;
30
32
  const model = this.body;
31
- model.emailAddress = model.email.verifyAddresses;
32
- model.phoneNumber = model.phone.verifyAddresses;
33
+ // first verify captcha...
33
34
  const w = await this.websiteService.getWebSite(this.request.hostName);
34
35
  const storeID = w.folderID;
35
36
  if (!storeID) {
36
37
  throw new EntityAccessError(`Signup not allowed`);
37
38
  }
38
- model.password = model.password?.trim();
39
39
  if (!model.emailAddress) {
40
40
  throw new EntityAccessError("Email is required");
41
41
  }
42
42
  model.phoneNumber = `+${model.phoneNumber.replace(/[^0-9]/g, "")}`;
43
- // check if phone number already exists...
43
+ let verificationGenerated = false;
44
+ if (!model.phone.verificationID) {
45
+ verificationGenerated = true;
46
+ // generate new one...
47
+ const vp = await this.otpService.create({ phone: model.phone.phone });
48
+ model.phone.verificationID = vp.id;
49
+ const v = await db.verificationTokens.where(vp, (p) => (x) => x.verificationID === p.id).first();
50
+ // inject public key
51
+ await this.sessionSecurity.injectPublicKey(v);
52
+ model.phone.accessCode = v.accessCode;
53
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
54
+ // @ts-expect-error
55
+ model.phone.$key = v.$key;
56
+ }
57
+ if (!model.email.verificationID) {
58
+ verificationGenerated = true;
59
+ const v = await this.evs.create({ email: model.emailAddress, ipAddress: this.request.remoteIPAddress });
60
+ model.email.verificationID = v.verificationID;
61
+ // @ts-expect-error unknown fields
62
+ model.email.$key = v.$key;
63
+ }
64
+ if (verificationGenerated) {
65
+ return this.json(model);
66
+ }
44
67
  for (const v1 of [model.captcha, model.email, model.phone]) {
45
68
  const { verificationID, accessCode } = v1;
46
69
  const vr = await db.verificationTokens.statements.select({}, { verificationID, accessCode });
@@ -62,9 +85,9 @@ let ExternalSignup = class ExternalSignup extends Page {
62
85
  if (exists) {
63
86
  throw new EntityAccessError(`Phone number is already registered.`);
64
87
  }
65
- model.password = randomUUID();
88
+ const password = randomUUID();
66
89
  const passwordSalt = this.cryptoService.generateSalt();
67
- const passwordHash = this.cryptoService.hash(passwordSalt, model.password);
90
+ const passwordHash = this.cryptoService.hash(passwordSalt, password);
68
91
  const dateCreated = DateTime.now;
69
92
  const phoneNumberE64 = model.phoneNumber;
70
93
  const name = model.name;
@@ -178,6 +201,14 @@ __decorate([
178
201
  Inject,
179
202
  __metadata("design:type", WebSiteContentService)
180
203
  ], ExternalSignup.prototype, "websiteService", void 0);
204
+ __decorate([
205
+ Inject,
206
+ __metadata("design:type", SessionSecurity)
207
+ ], ExternalSignup.prototype, "sessionSecurity", void 0);
208
+ __decorate([
209
+ Inject,
210
+ __metadata("design:type", EmailVerificationService)
211
+ ], ExternalSignup.prototype, "evs", void 0);
181
212
  ExternalSignup = __decorate([
182
213
  Prepare.parseJsonBody,
183
214
  Prepare.authorize
@@ -1 +1 @@
1
- {"version":3,"file":"post.js","sourceRoot":"","sources":["../../../../../../src/wwwroot/routes/social-mail/site/signup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,MAAM;8BACH,iBAAiB;0CAAC;AAGtB;IADC,MAAM;8BACS,qBAAqB;sDAAC;AAGtC;IADC,MAAM;8BACU,eAAe;uDAAC;AAGjC;IADC,MAAM;8BACF,wBAAwB;2CAAC;AAxBb,cAAc;IAFlC,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;GACG,cAAc,CAmNlC;eAnNoB,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.8.67",
3
+ "version": "1.8.72",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,7 +22,8 @@
22
22
  "@aws-sdk/client-s3": "^3.717.0",
23
23
  "@azure/storage-blob": "^12.25.0",
24
24
  "@entity-access/entity-access": "^1.0.499",
25
- "@entity-access/server-pages": "^1.1.504",
25
+ "@entity-access/server-pages": "^1.1.506",
26
+ "@paypal/paypal-server-sdk": "^1.0.0",
26
27
  "@peculiar/asn1-schema": "^2.3.15",
27
28
  "@social-mail/shared": "^1.0.29",
28
29
  "@socket.io/cluster-adapter": "^0.2.2",
@@ -66,6 +66,7 @@ export const globalEnv = {
66
66
  parentApiToken: process.env.SOCIAL_MAIL_PARENT_API_TOKEN,
67
67
  forceHttp1: false,
68
68
  isTestMode,
69
+ isLocalTestMode: process.env.SOCIAL_MAIL_LOCAL_TEST || false,
69
70
  puppeteer: {
70
71
  port: process.env.SOCIAL_MAIL_PUPPETEER_PORT || 8123,
71
72
  host: process.env.SOCIAL_MAIL_PUPPETEER_HOST || "puppeteer",
@@ -1,4 +1,4 @@
1
- import Index from "@entity-access/server-pages/dist/routes/api/entity/invoke/[entityName]/[methodName]/post.js";
1
+ import Index from "@entity-access/server-pages/dist/routes/api/entity/run/[entity]/[methodName]/index.js";
2
2
  import Inject from "@entity-access/entity-access/dist/di/di.js";
3
3
  import ReportDbContext from "../../../../../../../../../model/ReportDbContext.js";
4
4
 
@@ -34,6 +34,9 @@ export default class VerificationToken {
34
34
  @Column({ default: () => Sql.date.addMinutes(Sql.date.now(), 15)})
35
35
  expiry: DateTime;
36
36
 
37
+ @Column({ dataType: "Char", length: 200, nullable: true})
38
+ email: string;
39
+
37
40
  @Column({ dataType: "Char", length: 20, nullable: true})
38
41
  phone: string;
39
42
 
@@ -23,6 +23,7 @@ import OtpToUserService from "../../services/user/otp-to-user/OtpToUserService.j
23
23
  import SessionSecurity from "@entity-access/server-pages/dist/services/SessionSecurity.js";
24
24
  import EncryptionService from "../../services/encryption/EncryptionService.js";
25
25
  import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
26
+ import EmailVerificationService from "../../services/user/email-verification/EmailVerificationService.js";
26
27
 
27
28
  export default class VerificationTokenEvents extends AuthenticatedEvents<VerificationToken> {
28
29
 
@@ -41,6 +42,9 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
41
42
  @Inject
42
43
  captchaService: CaptchaService;
43
44
 
45
+ @Inject
46
+ evs: EmailVerificationService;
47
+
44
48
  @ExternalInvoke
45
49
  async updatePhone(entity: VerificationToken, phone: string) {
46
50
  const { db } = this;
@@ -105,15 +109,10 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
105
109
  // }
106
110
 
107
111
  @ExternalInvoke
108
- async resendCode(entity: VerificationToken, id, accessCode: string) {
109
- if(entity.verificationID !== id || entity.accessCode !== accessCode) {
110
- throw new EntityAccessError("Invalid id/access code");
111
- }
112
+ async resendCode(entity: VerificationToken) {
112
113
  switch(entity.type) {
113
114
  case "email":
114
- const db = ServiceProvider.resolve(this, SocialMailContext);
115
- const entry = db.changeSet.getEntry(entity);
116
- await this.sendVerificationEmail(entity, entry);
115
+ await this.evs.send(entity);
117
116
  break;
118
117
  case "sms-to-user":
119
118
  const sp = ServiceProvider.resolve(this, OtpToUserService);
@@ -128,13 +127,11 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
128
127
  }
129
128
 
130
129
  @ExternalInvoke
131
- async verifyCode(entity: VerificationToken, id: number, accessCode: string, code: string) {
132
- if(entity.verificationID !== id || entity.accessCode !== accessCode) {
133
- throw new EntityAccessError("Invalid id/access code");
134
- }
135
-
130
+ async verifyCode(entity: VerificationToken, code: string) {
136
131
  const db = ServiceProvider.resolve(this, SocialMailContext);
137
132
 
133
+ const id = entity.verificationID;
134
+
138
135
  switch(entity.type) {
139
136
  case "captcha":
140
137
  if(entity.code !== code) {
@@ -152,8 +149,6 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
152
149
  if(entity.code !== code) {
153
150
  throw new EntityAccessError("Invalid code");
154
151
  }
155
- const address = await db.verificationTokenAddresses.where({ id }, (p) => (x) => x.verificationID === p.id)
156
- .first();
157
152
 
158
153
  const ws = ServiceProvider.resolve(this, WebSiteContentService);
159
154
  const page = ServiceProvider.resolve(this, Page as any) as Page;
@@ -161,8 +156,9 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
161
156
  if(page?.request?.hostName) {
162
157
  const w = await ws.getWebSite(page.request.hostName);
163
158
  if (w) {
159
+ const { email } = entity;
164
160
  webSiteFolderID = w.folderID;
165
- const user = await db.users.where({ webSiteFolderID, email: address.address }, (p) => (x) =>
161
+ const user = await db.users.where({ webSiteFolderID, email }, (p) => (x) =>
166
162
  x.storeAccount.storeID === p.webSiteFolderID
167
163
  && x.storeAccount.emails.some((e) =>
168
164
  e.emailAddress.emailAddress === p.email
@@ -311,11 +307,13 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
311
307
  console.log(`Email Code is ${entity.code}`);
312
308
  entity.accessCode = randomUUID();
313
309
 
314
- entity.addresses = [
315
- db.verificationTokenAddresses.add({
316
- address: entity.verifyAddresses
317
- })
318
- ];
310
+ if (!entity.email) {
311
+ entity.addresses = [
312
+ db.verificationTokenAddresses.add({
313
+ address: entity.verifyAddresses
314
+ })
315
+ ];
316
+ }
319
317
 
320
318
  break;
321
319
  // case "sms":
@@ -356,7 +354,7 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
356
354
  // we need to make sure we are sending email..
357
355
  switch(entity.type) {
358
356
  case "email":
359
- await this.sendVerificationEmail(entity, entry);
357
+ await this.evs.send(entity);
360
358
  break;
361
359
  case "sms-to-user":
362
360
  if (entity.phone) {
@@ -366,37 +364,6 @@ export default class VerificationTokenEvents extends AuthenticatedEvents<Verific
366
364
  }
367
365
  }
368
366
 
369
- async sendVerificationEmail(entity: VerificationToken, entry: ChangeEntry<VerificationToken>) {
370
- if (entity.type !== "email") {
371
- throw new EntityAccessError(`Invalid verification type`);
372
- }
373
- const db = ServiceProvider.resolve(this, SocialMailContext);
374
- await entry.loadNavigationAsync((x) => x.addresses);
375
-
376
- const senderEmail = globalEnv.senderEmailForNotification;
377
- if (!senderEmail) {
378
- throw new EntityAccessError(`Sender for Notification is not set, cannot send email.`);
379
- }
380
-
381
- const textBody = `Social Mail Verification Code for your request is ${entity.code}`;
382
- const htmlBody = `<pre>Social Mail Verification Code for<br/>your request is ${entity.code}</pre>`;
383
-
384
- const ms = ServiceProvider.resolve(this, MailService);
385
-
386
- const eas = ServiceProvider.resolve(this, EmailAddressService);
387
- const hosted = await eas.getHostedMailboxID(senderEmail);
388
-
389
- await ms.sendNotificationEmail(`notify-email-${entity.verificationID}-${Date.now().toFixed(0)}`, {
390
- from: senderEmail,
391
- fromName: "Social Mail Verification Code",
392
- subject: "Social Mail Verification Code",
393
- htmlBody,
394
- textBody,
395
- to: entity.addresses[0].address,
396
- external: !hosted
397
- });
398
- }
399
-
400
367
  preJson(entity: VerificationToken): VerificationToken {
401
368
  entity.externalID = void 0;
402
369
  const { code, verificationID } = entity;
@@ -44,6 +44,10 @@ export default async function seed() {
44
44
 
45
45
  if (!migrated) {
46
46
  // using fast start
47
+ // const configService = scope.resolve(DBConfig);
48
+ if (globalEnv.isLocalTestMode) {
49
+ await seedUI(scope.resolve(DBConfig));
50
+ }
47
51
  return;
48
52
  }
49
53
 
@@ -5,7 +5,7 @@ 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.237"
8
+ version: "1.8.244"
9
9
  });
10
10
 
11
11
  await config.saveVersion(WebComponentsPackageConfig, {
@@ -1,87 +1,169 @@
1
- import Inject from "@entity-access/entity-access/dist/di/di.js";
1
+ import Inject, { RegisterSingleton } from "@entity-access/entity-access/dist/di/di.js";
2
2
  import { StoreJournal } from "../../../model/entities/StoreJournal.js";
3
3
  import StorePaymentAttempt from "../../../model/entities/StorePaymentAttempt.js";
4
4
  import StorePaymentGateway from "../../../model/entities/StorePaymentGateway.js";
5
5
  import EncryptionService from "../../encryption/EncryptionService.js";
6
6
  import LedgerPaymentGateway from "../LedgerPaymentGateway.js";
7
- import FetchBuilder from "@web-atoms/fetch-builder";
8
7
  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";
8
+ import { CaptureStatus, CheckoutPaymentIntent, Client, Environment, OrdersController, OrderStatus, PayeePaymentMethodPreference, PaypalExperienceLandingPage, PaypalExperienceUserAction } from "@paypal/paypal-server-sdk";
9
+ import TimedCache from "@entity-access/entity-access/dist/common/cache/TimedCache.js";
10
+
11
+ @RegisterSingleton
12
+ class PaypalClientCache {
13
+
14
+ cache = new TimedCache<any, Client>();
15
+
16
+ @Inject
17
+ ecs: EncryptionService;
18
+
19
+ getClient(gateway: StorePaymentGateway) {
20
+ return this.cache.getOrCreate(gateway.accountID, gateway, (k, p) => {
21
+ const secret = this.ecs.secure.decrypt(p.encryptedSecret);
22
+
23
+ return new Client({
24
+ environment: gateway.url ? Environment.Sandbox : Environment.Production,
25
+ clientCredentialsAuthCredentials: {
26
+ oAuthClientId: gateway.clientID,
27
+ oAuthClientSecret: secret
28
+ }
29
+ });
30
+ })
31
+ }
32
+
33
+ }
12
34
 
13
35
  export default class extends LedgerPaymentGateway {
14
36
 
15
37
  @Inject
16
38
  ecs: EncryptionService;
17
39
 
40
+ @Inject
41
+ pc: PaypalClientCache;
42
+
18
43
  @Inject
19
44
  db: SocialMailContext;
20
45
 
21
46
 
22
47
  async createPayment(host: string, gateway: StorePaymentGateway, order: StoreJournal, pa: StorePaymentAttempt) {
23
48
 
24
- const secret = this.ecs.secure.decrypt(gateway.encryptedSecret);
25
-
26
49
  const pID = this.ecs.general.encrypt(pa.attemptID.toString());
27
50
 
28
51
  const items = await this.db.storeJournalLineItems.where(order, (p) => (x) => x.journalID === p.journalID)
29
52
  .include((x) => x.itemPrice.storeItem)
30
53
  .toArray();
31
54
 
32
- const { emailAddress: { emailAddress: email_address}} = await this.db.storeAccountEmails
55
+ const client = this.pc.getClient(gateway);
56
+
57
+ const { emailAddress: { emailAddress: emailAddress}} = await this.db.storeAccountEmails
33
58
  .where(order, (p) => (x) => x.accountID === p.buyerID)
34
59
  .include((x) => x.emailAddress)
35
60
  .first();
36
61
 
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}`,
62
+ const orders = new OrdersController(client);
63
+
64
+ const currencyCode = items[0].itemPrice.currency;
65
+
66
+ const returnUrl = `https://${host}/store/checkout-callback/${pID}`;
67
+ const cancelUrl = `https://${host}/store/checkout-callback/${pID}`;
68
+
69
+
70
+ const pr = await orders.createOrder({
71
+ body: {
72
+ intent: CheckoutPaymentIntent.Capture,
73
+ paymentSource: {
74
+ paypal: {
75
+ experienceContext: {
76
+ paymentMethodPreference: PayeePaymentMethodPreference.ImmediatePaymentRequired,
77
+ brandName: host,
78
+ landingPage: PaypalExperienceLandingPage.NoPreference,
79
+ userAction: PaypalExperienceUserAction.PayNow,
80
+ returnUrl,
81
+ cancelUrl,
82
+ },
83
+ emailAddress
84
+ }
85
+ },
86
+ // applicationContext: {
87
+ // brandName: host,
88
+ // paymentMethod: {
89
+ // payeePreferred: PayeePaymentMethodPreference.Unrestricted,
90
+ // },
91
+ // landingPage: OrderApplicationContextLandingPage.Billing,
92
+ // userAction: OrderApplicationContextUserAction.PayNow,
93
+ // returnUrl,
94
+ // cancelUrl,
95
+ // },
96
+ purchaseUnits: [{
97
+ invoiceId: `${order.journalID}`,
98
+ referenceId: `${order.journalID}`,
99
+ amount: {
100
+ currencyCode,
101
+ value: order.total.toString(2),
102
+ breakdown: {
103
+ itemTotal: {
104
+ currencyCode,
105
+ value: order.total.toString(2)
106
+ }
107
+ }
52
108
  },
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>);
109
+ items: items.map((x) => ({
110
+ name: x.item.name,
111
+ quantity: Number(`${x.quantity || 1}`).toFixed(0),
112
+ currency: x.itemPrice.currency,
113
+ unitAmount: {
114
+ currencyCode,
115
+ value: (Number(x.total) / x.quantity).toFixed(2)
116
+ },
117
+ }))
118
+ }]
119
+ }
120
+ });
121
+
122
+ const link = pr.result.links.find((x) => x.rel === "payer-action");
123
+
124
+ pa.externalID = pr.result.id;
125
+
126
+ await this.db.storePaymentAttempts.statements.update({ externalID: pa.externalID }, { attemptID: pa.attemptID });
127
+
128
+ return {
129
+ url: link.href
130
+ };
131
+
132
+ // return Content.html(<HtmlDocument>
133
+ // <head>
134
+ // <title>Preparing Paypal Order</title>
135
+ // </head>
136
+ // <body>
137
+ // <script>
138
+ // location.href = {JSON.stringify(link.href)};
139
+ // </script>
140
+ // </body>
141
+ // </HtmlDocument>);
82
142
  }
83
- isSuccessful(pa: StorePaymentAttempt) {
84
- throw new Error("Method not implemented.");
143
+
144
+ async isSuccessful(pa: StorePaymentAttempt) {
145
+
146
+ const { gateway, externalID: id } = pa;
147
+
148
+ const client = this.pc.getClient(gateway);
149
+
150
+ const oc = new OrdersController(client);
151
+
152
+ let pr = await oc.getOrder({ id });
153
+
154
+ if (pr.result.status === OrderStatus.Approved) {
155
+ // let us capture...
156
+ pr = await oc.captureOrder({ id });
157
+ }
158
+
159
+ return pr.result
160
+ .purchaseUnits
161
+ .every((x) => x.payments
162
+ .captures
163
+ .every((c) => c.status === CaptureStatus.Completed));
164
+ // console.log(captures);
165
+
166
+ // throw new Error("Method not implemented.");
85
167
  }
86
168
 
87
169
  }
@@ -0,0 +1,78 @@
1
+ import Inject, { RegisterScoped, ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
2
+ import VerificationToken from "../../../model/entities/VerificationToken.js";
3
+ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
+ import { globalEnv } from "../../../../common/globalEnv.js";
5
+ import SocialMailContext from "../../../model/SocialMailContext.js";
6
+ import EmailAddressService from "../../EmailAddressService.js";
7
+ import MailService from "../../emails/MailService.js";
8
+ import SessionSecurity from "@entity-access/server-pages/dist/services/SessionSecurity.js";
9
+ import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
10
+
11
+ @RegisterScoped
12
+ export default class EmailVerificationService {
13
+
14
+ @Inject
15
+ db: SocialMailContext;
16
+
17
+ @Inject
18
+ eas: EmailAddressService;
19
+
20
+ @Inject
21
+ ms: MailService;
22
+
23
+ @Inject
24
+ sessionSecurity: SessionSecurity;
25
+
26
+ async create({ email, ipAddress }) {
27
+
28
+ let code = Date.now().toString();
29
+ code = code.substring(code.length-5);
30
+
31
+ console.log(`Email Code is ${code}`);
32
+
33
+ const v = await this.db.verificationTokens.statements.insert({
34
+ type: "email",
35
+ email,
36
+ code,
37
+ dateCreated: DateTime.now,
38
+ ipAddress
39
+ });
40
+
41
+ // send..
42
+ await this.send(v);
43
+
44
+ this.sessionSecurity.injectPublicKey(v);
45
+ v.code = void 0;
46
+ v.ipAddress = void 0;
47
+ return v;
48
+ }
49
+
50
+
51
+ async send(entity: VerificationToken) {
52
+ if (entity.type !== "email") {
53
+ throw new EntityAccessError(`Invalid verification type`);
54
+ }
55
+
56
+ const senderEmail = globalEnv.senderEmailForNotification;
57
+ if (!senderEmail) {
58
+ throw new EntityAccessError(`Sender for Notification is not set, cannot send email.`);
59
+ }
60
+
61
+ const textBody = `Social Mail Verification Code for your request is ${entity.code}`;
62
+ const htmlBody = `<pre>Social Mail Verification Code for<br/>your request is ${entity.code}</pre>`;
63
+
64
+ const { eas, ms } = this;
65
+
66
+ const hosted = await eas.getHostedMailboxID(senderEmail);
67
+
68
+ await ms.sendNotificationEmail(`notify-email-${entity.verificationID}-${Date.now().toFixed(0)}`, {
69
+ from: senderEmail,
70
+ fromName: "Social Mail Verification Code",
71
+ subject: "Social Mail Verification Code",
72
+ htmlBody,
73
+ textBody,
74
+ to: entity.email,
75
+ external: !hosted
76
+ });
77
+ }
78
+ }