@chevre/domain 21.7.0-alpha.9 → 21.8.0-alpha.0

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 (55) hide show
  1. package/example/src/chevre/countDelayedTasks.ts +1 -1
  2. package/example/src/chevre/createDeleteTransactionTasks.ts +108 -0
  3. package/example/src/chevre/createDeleteTransactionTasksIfNotExist.ts +98 -0
  4. package/example/src/chevre/deleteRunsAtPassedCertainPeriod.ts +28 -0
  5. package/example/src/chevre/deleteTasksByName.ts +1 -1
  6. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +1 -1
  7. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +4 -1
  8. package/example/src/chevre/unsetUnnecessaryFields.ts +1 -1
  9. package/lib/chevre/emailMessageBuilder.js +2 -1
  10. package/lib/chevre/repo/assetTransaction.js +22 -23
  11. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +4 -4
  12. package/lib/chevre/repo/mongoose/schemas/offer.js +5 -6
  13. package/lib/chevre/repo/project.d.ts +1 -0
  14. package/lib/chevre/repo/project.js +10 -4
  15. package/lib/chevre/repo/task.d.ts +6 -2
  16. package/lib/chevre/repo/task.js +25 -1
  17. package/lib/chevre/repo/transaction.d.ts +25 -1
  18. package/lib/chevre/repo/transaction.js +6 -1
  19. package/lib/chevre/service/notification.js +13 -6
  20. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +20 -0
  21. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +242 -1
  22. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -1
  23. package/lib/chevre/service/order/onOrderStatusChanged.js +139 -110
  24. package/lib/chevre/service/order/payOrder.d.ts +23 -0
  25. package/lib/chevre/service/order/payOrder.js +74 -0
  26. package/lib/chevre/service/order/placeOrder.d.ts +1 -3
  27. package/lib/chevre/service/order/placeOrder.js +33 -76
  28. package/lib/chevre/service/order/returnOrder.d.ts +1 -2
  29. package/lib/chevre/service/order/returnOrder.js +15 -97
  30. package/lib/chevre/service/order/sendOrder.d.ts +0 -1
  31. package/lib/chevre/service/order/sendOrder.js +6 -68
  32. package/lib/chevre/service/payment/any/factory.js +3 -2
  33. package/lib/chevre/service/task/confirmPayTransaction.js +56 -0
  34. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  35. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +6 -6
  36. package/lib/chevre/service/transaction/moneyTransfer/factory.js +1 -5
  37. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  38. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +12 -6
  39. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +4 -0
  40. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +92 -88
  41. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +1 -1
  42. package/lib/chevre/service/transaction/placeOrderInProgress.js +0 -2
  43. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +8 -1
  44. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +7 -4
  45. package/lib/chevre/service/transaction/returnOrder.js +0 -1
  46. package/lib/chevre/settings.d.ts +1 -1
  47. package/lib/chevre/settings.js +2 -2
  48. package/package.json +3 -3
  49. package/example/src/chevre/checkOrderMembershipTasks.ts +0 -127
  50. package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +0 -65
  51. package/example/src/chevre/transaction/orderMembershipService.ts +0 -105
  52. package/lib/chevre/service/task/orderProgramMembership.d.ts +0 -6
  53. package/lib/chevre/service/task/orderProgramMembership.js +0 -98
  54. package/lib/chevre/service/transaction/orderProgramMembership.d.ts +0 -50
  55. package/lib/chevre/service/transaction/orderProgramMembership.js +0 -349
@@ -1,105 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
- import * as redis from 'redis';
4
-
5
- import { chevre } from '../../../../lib/index';
6
-
7
- import { orderProgramMembership } from '../../../../lib/chevre/service/transaction/orderProgramMembership';
8
-
9
- const project = { id: String(process.env.PROJECT_ID) };
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY
19
- });
20
- await redisClient.connect();
21
-
22
- const personRepo = new chevre.repository.Person({ userPoolId: chevre.settings.settings.userPoolIdNew });
23
- const actionRepo = new chevre.repository.Action(mongoose.connection);
24
- const accountRepo = new chevre.repository.Account(mongoose.connection);
25
- const accountingReportRepo = new chevre.repository.AccountingReport(mongoose.connection);
26
- const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
27
- const eventRepo = new chevre.repository.Event(mongoose.connection);
28
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
29
- const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
30
- const productRepo = new chevre.repository.Product(mongoose.connection);
31
- const projectRepo = new chevre.repository.Project(mongoose.connection);
32
- const ownershipInfoRepo = new chevre.repository.OwnershipInfo(mongoose.connection);
33
- const sellerRepo = new chevre.repository.Seller(mongoose.connection);
34
- const serviceOutputRepo = new chevre.repository.ServiceOutput(mongoose.connection);
35
- const taskRepo = new chevre.repository.Task(mongoose.connection);
36
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
37
- const confirmationNumberRepo = new chevre.repository.ConfirmationNumber(redisClient);
38
- const orderNumberRepo = new chevre.repository.OrderNumber(redisClient);
39
- const registerServiceInProgressRepo = new chevre.repository.action.RegisterServiceInProgress(redisClient);
40
- const transactionNumberRepo = new chevre.repository.TransactionNumber(redisClient);
41
- const serviceOutputIdentifierRepo = new chevre.repository.ServiceOutputIdentifier(redisClient);
42
-
43
- const result = await orderProgramMembership(
44
- {
45
- agent: {
46
- typeOf: chevre.factory.personType.Person,
47
- id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e',
48
- identifier: [
49
- {
50
- name: 'iss',
51
- value: String(process.env.ISS)
52
- }
53
- ]
54
- },
55
- object: {
56
- seller: {
57
- id: '5d0abf30ac3fb200198ebb2c'
58
- },
59
- typeOf: chevre.factory.offerType.Offer,
60
- itemOffered: {
61
- typeOf: chevre.factory.permit.PermitType.Permit,
62
- name: '[development]会員ポイントプログラム',
63
- issuedThrough: {
64
- id: '5afff104d51e59232c7b481b',
65
- typeOf: chevre.factory.product.ProductType.MembershipService
66
- }
67
- },
68
- id: '7k9f3ht34',
69
- identifier: 'AnnualPlan'
70
- },
71
- project: {
72
- typeOf: chevre.factory.organizationType.Project,
73
- id: project.id
74
- },
75
- typeOf: chevre.factory.actionType.OrderAction
76
- },
77
- 'CreditCard'
78
- )({
79
- account: accountRepo,
80
- accountingReport: accountingReportRepo,
81
- action: actionRepo,
82
- assetTransaction: assetTransactionRepo,
83
- confirmationNumber: confirmationNumberRepo,
84
- event: eventRepo,
85
- offer: offerRepo,
86
- offerCatalog: offerCatalogRepo,
87
- orderNumber: orderNumberRepo,
88
- ownershipInfo: ownershipInfoRepo,
89
- person: personRepo,
90
- product: productRepo,
91
- project: projectRepo,
92
- registerActionInProgress: registerServiceInProgressRepo,
93
- seller: sellerRepo,
94
- serviceOutput: serviceOutputRepo,
95
- serviceOutputIdentifier: serviceOutputIdentifierRepo,
96
- task: taskRepo,
97
- transaction: transactionRepo,
98
- transactionNumber: transactionNumberRepo
99
- });
100
- console.log(result);
101
- }
102
-
103
- main()
104
- .then(console.log)
105
- .catch(console.error);
@@ -1,6 +0,0 @@
1
- import { IOperation } from '../task';
2
- import * as factory from '../../factory';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.IData<factory.taskName.OrderProgramMembership>): IOperation<void>;
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.call = void 0;
13
- const account_1 = require("../../repo/account");
14
- const accountingReport_1 = require("../../repo/accountingReport");
15
- const action_1 = require("../../repo/action");
16
- const assetTransaction_1 = require("../../repo/assetTransaction");
17
- const event_1 = require("../../repo/event");
18
- const offer_1 = require("../../repo/offer");
19
- const offerCatalog_1 = require("../../repo/offerCatalog");
20
- const ownershipInfo_1 = require("../../repo/ownershipInfo");
21
- const person_1 = require("../../repo/person");
22
- const product_1 = require("../../repo/product");
23
- const project_1 = require("../../repo/project");
24
- const seller_1 = require("../../repo/seller");
25
- const serviceOutput_1 = require("../../repo/serviceOutput");
26
- const task_1 = require("../../repo/task");
27
- const transaction_1 = require("../../repo/transaction");
28
- const registerServiceInProgress_1 = require("../../repo/action/registerServiceInProgress");
29
- const confirmationNumber_1 = require("../../repo/confirmationNumber");
30
- const orderNumber_1 = require("../../repo/orderNumber");
31
- const serviceOutputIdentifier_1 = require("../../repo/serviceOutputIdentifier");
32
- const transactionNumber_1 = require("../../repo/transactionNumber");
33
- const orderProgramMembership_1 = require("../../service/transaction/orderProgramMembership");
34
- const settings_1 = require("../../settings");
35
- /**
36
- * タスク実行関数
37
- */
38
- function call(data) {
39
- // tslint:disable-next-line:max-func-body-length
40
- return (settings) => __awaiter(this, void 0, void 0, function* () {
41
- var _a, _b;
42
- // tslint:disable-next-line:no-single-line-block-comment
43
- /* istanbul ignore if */
44
- if (settings.redisClient === undefined) {
45
- throw new Error('settings.redisClient undefined.');
46
- }
47
- let iss = '';
48
- if (Array.isArray(data.agent.identifier)) {
49
- const issByAgent = (_b = (_a = data.agent.identifier) === null || _a === void 0 ? void 0 : _a.find((p) => p.name === 'iss')) === null || _b === void 0 ? void 0 : _b.value;
50
- if (typeof issByAgent === 'string' && issByAgent.length > 0) {
51
- iss = issByAgent.replace(orderProgramMembership_1.ISS_PREFIX, '');
52
- }
53
- }
54
- const personRepo = new person_1.CognitoRepository({ userPoolId: iss });
55
- const accountingReportRepo = new accountingReport_1.MongoRepository(settings.connection);
56
- const actionRepo = new action_1.MongoRepository(settings.connection);
57
- const accountRepo = new account_1.MongoRepository(settings.connection);
58
- const assetTransactionRepo = new assetTransaction_1.MongoRepository(settings.connection);
59
- const eventRepo = new event_1.MongoRepository(settings.connection);
60
- const offerRepo = new offer_1.MongoRepository(settings.connection);
61
- const offerCatalogRepo = new offerCatalog_1.MongoRepository(settings.connection);
62
- const productRepo = new product_1.MongoRepository(settings.connection);
63
- const projectRepo = new project_1.MongoRepository(settings.connection);
64
- const ownershipInfoRepo = new ownershipInfo_1.MongoRepository(settings.connection);
65
- const sellerRepo = new seller_1.MongoRepository(settings.connection);
66
- const serviceOutputRepo = new serviceOutput_1.MongoRepository(settings.connection);
67
- const taskRepo = new task_1.MongoRepository(settings.connection);
68
- const transactionRepo = new transaction_1.MongoRepository(settings.connection);
69
- const confirmationNumberRepo = new confirmationNumber_1.RedisRepository(settings.redisClient);
70
- const orderNumberRepo = new orderNumber_1.RedisRepository(settings.redisClient);
71
- const registerServiceInProgressRepo = new registerServiceInProgress_1.RedisRepository(settings.redisClient);
72
- const transactionNumberRepo = new transactionNumber_1.RedisRepository(settings.redisClient);
73
- const serviceOutputIdentifierRepo = new serviceOutputIdentifier_1.RedisRepository(settings.redisClient);
74
- yield (0, orderProgramMembership_1.orderProgramMembership)(data, settings_1.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD)({
75
- account: accountRepo,
76
- accountingReport: accountingReportRepo,
77
- action: actionRepo,
78
- assetTransaction: assetTransactionRepo,
79
- confirmationNumber: confirmationNumberRepo,
80
- event: eventRepo,
81
- offer: offerRepo,
82
- offerCatalog: offerCatalogRepo,
83
- orderNumber: orderNumberRepo,
84
- ownershipInfo: ownershipInfoRepo,
85
- person: personRepo,
86
- product: productRepo,
87
- project: projectRepo,
88
- registerActionInProgress: registerServiceInProgressRepo,
89
- seller: sellerRepo,
90
- serviceOutput: serviceOutputRepo,
91
- serviceOutputIdentifier: serviceOutputIdentifierRepo,
92
- task: taskRepo,
93
- transaction: transactionRepo,
94
- transactionNumber: transactionNumberRepo
95
- });
96
- });
97
- }
98
- exports.call = call;
@@ -1,50 +0,0 @@
1
- import { MongoRepository as AccountRepo } from '../../repo/account';
2
- import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
3
- import { MongoRepository as ActionRepo } from '../../repo/action';
4
- import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
5
- import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
6
- import { RedisRepository as ConfirmationNumberRepo } from '../../repo/confirmationNumber';
7
- import { MongoRepository as EventRepo } from '../../repo/event';
8
- import { MongoRepository as OfferRepo } from '../../repo/offer';
9
- import { MongoRepository as OfferCatalogRepo } from '../../repo/offerCatalog';
10
- import { RedisRepository as OrderNumberRepo } from '../../repo/orderNumber';
11
- import { MongoRepository as OwnershipInfoRepo } from '../../repo/ownershipInfo';
12
- import { CognitoRepository as PersonRepo } from '../../repo/person';
13
- import { MongoRepository as ProductRepo } from '../../repo/product';
14
- import { MongoRepository as ProjectRepo } from '../../repo/project';
15
- import { MongoRepository as SellerRepo } from '../../repo/seller';
16
- import { MongoRepository as ServiceOutputRepo } from '../../repo/serviceOutput';
17
- import { RedisRepository as ServiceOutputIdentifierRepo } from '../../repo/serviceOutputIdentifier';
18
- import { MongoRepository as TaskRepo } from '../../repo/task';
19
- import { MongoRepository as TransactionRepo } from '../../repo/transaction';
20
- import { RedisRepository as TransactionNumberRepo } from '../../repo/transactionNumber';
21
- import * as factory from '../../factory';
22
- export declare const ISS_PREFIX = "https://cognito-idp.ap-northeast-1.amazonaws.com/";
23
- interface IOrderOperationRepos {
24
- account: AccountRepo;
25
- accountingReport: AccountingReportRepo;
26
- action: ActionRepo;
27
- assetTransaction: AssetTransactionRepo;
28
- confirmationNumber: ConfirmationNumberRepo;
29
- event: EventRepo;
30
- offer: OfferRepo;
31
- offerCatalog: OfferCatalogRepo;
32
- orderNumber: OrderNumberRepo;
33
- ownershipInfo: OwnershipInfoRepo;
34
- person: PersonRepo;
35
- product: ProductRepo;
36
- project: ProjectRepo;
37
- registerActionInProgress: RegisterServiceInProgressRepo;
38
- seller: SellerRepo;
39
- serviceOutput: ServiceOutputRepo;
40
- serviceOutputIdentifier: ServiceOutputIdentifierRepo;
41
- task: TaskRepo;
42
- transaction: TransactionRepo;
43
- transactionNumber: TransactionNumberRepo;
44
- }
45
- type IOrderOperation<T> = (repos: IOrderOperationRepos) => Promise<T>;
46
- /**
47
- * メンバーシップ注文
48
- */
49
- export declare function orderProgramMembership(params: factory.task.IData<factory.taskName.OrderProgramMembership>, paymentMethodType: string): IOrderOperation<void>;
50
- export {};
@@ -1,349 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.orderProgramMembership = exports.ISS_PREFIX = void 0;
13
- /**
14
- * メンバーシップ注文サービス
15
- */
16
- const GMO = require("@motionpicture/gmo-service");
17
- const createDebug = require("debug");
18
- const accountTransactionIdentifier_1 = require("../../factory/accountTransactionIdentifier");
19
- const OfferService = require("../offer");
20
- const AnyPaymentService = require("../payment/any");
21
- const TransactionService = require("../transaction");
22
- const findCreditCard_1 = require("./orderProgramMembership/findCreditCard");
23
- const findPaymentCardPermit_1 = require("./orderProgramMembership/findPaymentCardPermit");
24
- const factory = require("../../factory");
25
- // import { credentials } from '../../credentials';
26
- // import { settings } from '../../settings';
27
- const debug = createDebug('chevre-domain:service:orderProgramMembership');
28
- exports.ISS_PREFIX = 'https://cognito-idp.ap-northeast-1.amazonaws.com/';
29
- /**
30
- * メンバーシップ注文
31
- */
32
- function orderProgramMembership(params, paymentMethodType) {
33
- return (repos) => __awaiter(this, void 0, void 0, function* () {
34
- var _a, _b, _c;
35
- let customer;
36
- try {
37
- customer = yield repos.person.findById({ userId: String(params.agent.id) });
38
- }
39
- catch (error) {
40
- // Not Found: User.をハンドル(2023-03-31~)
41
- if (error instanceof factory.errors.NotFound) {
42
- // no op
43
- }
44
- else {
45
- throw error;
46
- }
47
- }
48
- if (customer === undefined) {
49
- // Userが存在しなければリトライは不要
50
- return;
51
- }
52
- // issに依存するので存在確認
53
- const issByCustomer = (_b = (_a = customer.identifier) === null || _a === void 0 ? void 0 : _a.find((p) => p.name === 'iss')) === null || _b === void 0 ? void 0 : _b.value;
54
- if (typeof issByCustomer !== 'string' || issByCustomer.length === 0) {
55
- throw new factory.errors.NotFound(`iss of customer ${customer.id}`);
56
- }
57
- const acceptedOffer = params.object;
58
- const sellerId = (_c = acceptedOffer.seller) === null || _c === void 0 ? void 0 : _c.id;
59
- // if (typeof sellerId !== 'string') {
60
- // // 互換性維持対応として↓
61
- // sellerId = (<any>acceptedOffer.itemOffered)?.hostingOrganization?.id;
62
- // }
63
- if (typeof sellerId !== 'string') {
64
- throw new factory.errors.NotFound('acceptedOffer seller ID undefined');
65
- }
66
- let transaction;
67
- try {
68
- // 注文取引開始
69
- const startParams = createStartPlaceOrderInProgressParams({
70
- project: params.project,
71
- customer,
72
- seller: { id: sellerId }
73
- });
74
- transaction = yield TransactionService.placeOrderInProgress.start(startParams)(repos);
75
- // 取引ID上で注文プロセス
76
- yield processPlaceOrder({
77
- acceptedOffer: acceptedOffer,
78
- customer: customer,
79
- potentialActions: params.potentialActions,
80
- project: { id: params.project.id },
81
- transaction: transaction,
82
- paymentMethodType
83
- // iss
84
- })(repos);
85
- }
86
- catch (error) {
87
- debug('processPlaceOrder throwed an error.', error);
88
- try {
89
- if (typeof (transaction === null || transaction === void 0 ? void 0 : transaction.id) === 'string') {
90
- yield OfferService.product.voidTransaction({
91
- agent: { id: customer.id },
92
- project: { typeOf: factory.organizationType.Project, id: params.project.id },
93
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
94
- })(repos);
95
- }
96
- }
97
- catch (error) {
98
- // 失敗したら仕方ない
99
- }
100
- // 決済に関してクライアントエラーであれば、リトライしても無駄なので、正常終了
101
- if (error instanceof factory.errors.Argument
102
- && (error.argumentName === 'payment' || error.argumentName === 'ChevreArgument')) {
103
- return;
104
- }
105
- // すでに登録済のエラーハンドリング
106
- if (error instanceof factory.errors.Argument && error.message
107
- === OfferService.product.ERROR_MESSAGE_ALREADY_REGISTERED) {
108
- return;
109
- }
110
- // Not Found: OwnershipInfos of PaymentCard.をハンドル(2023-03-31~)
111
- if (error instanceof factory.errors.NotFound && error.entityName === 'OwnershipInfos of PaymentCard') {
112
- return;
113
- }
114
- throw error;
115
- }
116
- });
117
- }
118
- exports.orderProgramMembership = orderProgramMembership;
119
- function createStartPlaceOrderInProgressParams(params) {
120
- var _a;
121
- const customer = params.customer;
122
- const agent = {
123
- typeOf: customer.typeOf,
124
- id: customer.id,
125
- identifier: customer.identifier,
126
- memberOf: customer.memberOf
127
- };
128
- return {
129
- project: { typeOf: factory.organizationType.Project, id: params.project.id },
130
- // expiresInSeconds指定に変更(2022-11-29~)
131
- // expires: moment()
132
- // // tslint:disable-next-line:no-magic-numbers
133
- // .add(5, 'minutes')
134
- // .toDate(),
135
- expiresInSeconds: 300,
136
- agent,
137
- seller: { id: params.seller.id },
138
- object: {
139
- customer: Object.assign(Object.assign({ typeOf: customer.typeOf, id: customer.id }, (Array.isArray(customer.identifier)) ? { identifier: customer.identifier } : undefined), (typeof ((_a = customer.memberOf) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { memberOf: customer.memberOf } : undefined)
140
- },
141
- validateSeller: false
142
- };
143
- }
144
- /**
145
- * メンバーシップを注文する
146
- */
147
- function processPlaceOrder(params) {
148
- return (repos) => __awaiter(this, void 0, void 0, function* () {
149
- var _a, _b, _c;
150
- const now = new Date();
151
- const acceptedOffer = params.acceptedOffer;
152
- const customer = params.customer;
153
- const transaction = params.transaction;
154
- // プロダクト情報取得
155
- // membershipForへの依存排除
156
- let productId = (_a = acceptedOffer.itemOffered.issuedThrough) === null || _a === void 0 ? void 0 : _a.id;
157
- if (typeof productId !== 'string') {
158
- // 互換性維持対応として↓
159
- productId = (_b = acceptedOffer.itemOffered.membershipFor) === null || _b === void 0 ? void 0 : _b.id;
160
- }
161
- if (typeof productId !== 'string') {
162
- throw new Error('acceptedOffer.itemOffered.issuedThrough.id or acceptedOffer.itemOffered.membershipFor.id undefined');
163
- }
164
- // 注文番号を先に発行
165
- const orderNumber = yield TransactionService.placeOrderInProgress.publishOrderNumberIfNotExist({
166
- project: { id: transaction.project.id },
167
- id: transaction.id,
168
- object: { orderDate: now }
169
- })(repos);
170
- // メンバーシップオファー承認
171
- let authorizeProductOfferAction;
172
- authorizeProductOfferAction = yield processAuthorizeProductOffer({
173
- project: { id: params.project.id },
174
- orderNumber,
175
- customer: customer,
176
- transaction: transaction,
177
- acceptedOffer: acceptedOffer,
178
- product: { id: productId },
179
- // iss: params.iss,
180
- now
181
- })(repos);
182
- const amount = Number((_c = authorizeProductOfferAction.result) === null || _c === void 0 ? void 0 : _c.price);
183
- if (amount > 0) {
184
- yield processAuthorizeCreditCard({
185
- project: { id: params.project.id },
186
- customer: customer,
187
- object: { amount },
188
- purpose: transaction,
189
- paymentMethodType: params.paymentMethodType
190
- // iss: params.iss
191
- })(repos);
192
- }
193
- yield TransactionService.updateAgent({
194
- typeOf: transaction.typeOf,
195
- id: transaction.id,
196
- agent: {
197
- typeOf: customer.typeOf,
198
- id: customer.id,
199
- email: customer.email,
200
- familyName: customer.familyName,
201
- givenName: customer.givenName,
202
- telephone: customer.telephone
203
- }
204
- })(repos);
205
- // 取引確定
206
- return TransactionService.placeOrderInProgress.confirm({
207
- project: { id: params.project.id },
208
- id: transaction.id,
209
- agent: { id: customer.id },
210
- result: {
211
- order: {
212
- // new DateにしないとここまでのAuthorizeActionが取引に含まれない
213
- orderDate: new Date()
214
- }
215
- },
216
- potentialActions: params.potentialActions
217
- })(repos);
218
- });
219
- }
220
- function processAuthorizeProductOffer(params) {
221
- return (repos) => __awaiter(this, void 0, void 0, function* () {
222
- var _a, _b, _c, _d;
223
- const acceptedOffer = params.acceptedOffer;
224
- const customer = params.customer;
225
- const transaction = params.transaction;
226
- const project = { typeOf: factory.organizationType.Project, id: params.project.id };
227
- const seller = {
228
- // project: project,
229
- typeOf: transaction.seller.typeOf,
230
- id: transaction.seller.id,
231
- name: transaction.seller.name
232
- };
233
- // オファーにポイント特典設定があるかどうか確認
234
- let pointAward;
235
- const { offers } = yield OfferService.product.search({
236
- project: { id: params.project.id },
237
- itemOffered: { id: params.product.id },
238
- seller: { id: String(seller.id) },
239
- onlyValid: true,
240
- addSortIndex: false
241
- })(repos);
242
- const acceptedProductOffer = offers.find((o) => o.identifier === acceptedOffer.identifier);
243
- if (acceptedProductOffer === undefined) {
244
- throw new factory.errors.NotFound('Offer', `Accepted offer ${acceptedOffer.identifier} not found`);
245
- }
246
- const pointAwardByOffer = (_a = acceptedProductOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.pointAward;
247
- const pointAwardAccountType = (_b = pointAwardByOffer === null || pointAwardByOffer === void 0 ? void 0 : pointAwardByOffer.amount) === null || _b === void 0 ? void 0 : _b.currency;
248
- if (typeof ((_c = pointAwardByOffer === null || pointAwardByOffer === void 0 ? void 0 : pointAwardByOffer.amount) === null || _c === void 0 ? void 0 : _c.value) === 'number' && typeof pointAwardAccountType === 'string') {
249
- const toPermit = yield (0, findPaymentCardPermit_1.findPaymentCardPermit)({
250
- customer: { id: params.customer.id },
251
- project: transaction.project,
252
- now: params.now,
253
- accountType: pointAwardAccountType
254
- // iss: params.iss
255
- })(repos);
256
- const identifier = (0, accountTransactionIdentifier_1.createPointAwardIdentifier)({
257
- project: params.project,
258
- purpose: { orderNumber: params.orderNumber },
259
- toLocation: { identifier: String(toPermit.identifier) }
260
- });
261
- const toLocationIssuedThroughId = (_d = toPermit.issuedThrough) === null || _d === void 0 ? void 0 : _d.id;
262
- if (typeof toLocationIssuedThroughId !== 'string' || toLocationIssuedThroughId.length === 0) {
263
- throw new factory.errors.NotFound('toPermit.issuedThrough.id');
264
- }
265
- pointAward = {
266
- typeOf: factory.actionType.MoneyTransfer,
267
- toLocation: {
268
- identifier: String(toPermit.identifier),
269
- issuedThrough: { id: toLocationIssuedThroughId },
270
- typeOf: factory.permit.PermitType.Permit
271
- },
272
- recipient: {
273
- id: customer.id,
274
- name: `${customer.givenName} ${customer.familyName}`,
275
- typeOf: customer.typeOf
276
- },
277
- // 特典識別子を指定(ユニークネスを保証するため)
278
- purpose: { identifier }
279
- };
280
- }
281
- const serviceOutputName = (typeof acceptedOffer.itemOffered.name === 'string')
282
- ? acceptedOffer.itemOffered.name
283
- : undefined;
284
- const object = [{
285
- // project: project,
286
- typeOf: acceptedProductOffer.typeOf,
287
- id: acceptedProductOffer.id,
288
- priceCurrency: acceptedProductOffer.priceCurrency,
289
- itemOffered: Object.assign({
290
- // project: project,
291
- typeOf: factory.product.ProductType.MembershipService, id: params.product.id, serviceOutput: Object.assign({ project: project, typeOf: acceptedOffer.itemOffered.typeOf }, (typeof serviceOutputName === 'string') ? { name: serviceOutputName } : undefined) }, (pointAward !== undefined) ? { pointAward } : undefined),
292
- seller: seller
293
- }];
294
- // メンバーシップオファー承認
295
- return OfferService.product.authorize({
296
- project: { typeOf: factory.organizationType.Project, id: params.project.id },
297
- agent: { id: customer.id, typeOf: customer.typeOf },
298
- object: object,
299
- transaction: { id: transaction.id }
300
- // iss: params.iss
301
- })(repos);
302
- });
303
- }
304
- function processAuthorizeCreditCard(params) {
305
- return (repos) => __awaiter(this, void 0, void 0, function* () {
306
- // 会員クレジットカード検索(事前にクレジットカードを登録しているはず)
307
- const creditCard = yield (0, findCreditCard_1.findCreditCard)({
308
- project: { id: params.project.id },
309
- customer: { id: params.customer.id },
310
- paymentMethodType: params.paymentMethodType
311
- })(repos);
312
- // 決済サービスを検索
313
- const searchCreditCardPaymentServicesResult = yield repos.product.search({
314
- limit: 1,
315
- page: 1,
316
- project: { id: { $eq: params.project.id } },
317
- typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard },
318
- serviceType: { codeValue: { $eq: params.paymentMethodType } }
319
- }, [], []);
320
- const creditCardPaymentService = searchCreditCardPaymentServicesResult.shift();
321
- if (creditCardPaymentService === undefined) {
322
- throw new factory.errors.NotFound('CreditCardPaymentService');
323
- }
324
- yield AnyPaymentService.authorize({
325
- project: { id: params.project.id },
326
- agent: params.customer,
327
- object: {
328
- typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment,
329
- paymentMethod: params.paymentMethodType,
330
- amount: params.object.amount,
331
- method: GMO.utils.util.Method.Lump,
332
- creditCard: {
333
- // memberId: creditCard.memberId, // chevre側で自動変換される
334
- memberId: params.customer.id,
335
- cardSeq: Number(creditCard.cardSeq)
336
- },
337
- issuedThrough: { id: String(creditCardPaymentService.id) }
338
- },
339
- purpose: params.purpose,
340
- paymentServiceType: factory.service.paymentService.PaymentServiceType.CreditCard,
341
- options: {
342
- useCancelPayTransactionOnFailed: false,
343
- useCheckMovieTicketBeforePay: false,
344
- useCheckByIdentifierIfNotYet: false,
345
- useSearchTrade4accountId: false
346
- }
347
- })(repos);
348
- });
349
- }