@cinerino/sdk 10.5.0 → 10.6.0-alpha.1

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 (24) hide show
  1. package/example/playground/public/lib/bundle.js +57 -3
  2. package/example/src/chevre/assetTransaction/processPayMovieTicket.ts +1 -1
  3. package/example/src/chevre/assetTransaction/processPublishPaymentUrl.ts +1 -1
  4. package/example/src/chevre/assetTransaction/processRefundCreditCard.ts +1 -1
  5. package/example/src/chevre/transaction/processPlaceOrder.ts +75 -52
  6. package/example/src/chevre/transaction/processPlaceOrderMembership.ts +1 -1
  7. package/example/src/chevre/transaction/{processPlaceOrderUsingMembership.ts → processPlaceOrderUsingTicketIssuedThroughFaceToFace.ts} +35 -14
  8. package/example/src/cloud/transaction/authorizeCreditCardAsyncForcibly.ts +74 -0
  9. package/example/src/cloud/transaction/processPlaceOrderUsingTicketIssuedThroughCreditCard.ts +239 -0
  10. package/example/src/cloud/transaction/processPlaceOrderUsingTicketIssuedThroughFaceToFace.ts +2 -2
  11. package/lib/abstract/chevre/seller/factory.d.ts +9 -1
  12. package/lib/abstract/chevre/seller.d.ts +11 -9
  13. package/lib/abstract/chevre/seller.js +18 -41
  14. package/lib/abstract/chevreAdmin/seller/factory.d.ts +0 -1
  15. package/lib/abstract/chevreAdmin/seller.d.ts +1 -14
  16. package/lib/abstract/chevreAdmin/seller.js +0 -28
  17. package/lib/abstract/chevrePay/payment/factory.d.ts +1 -1
  18. package/lib/abstract/chevrePay/payment.d.ts +11 -0
  19. package/lib/abstract/chevrePay/payment.js +22 -1
  20. package/lib/abstract/cloud/pay/payment.d.ts +14 -0
  21. package/lib/abstract/cloud/pay/payment.js +28 -0
  22. package/lib/bundle.js +69 -71
  23. package/package.json +2 -2
  24. package/example/src/chevre/searchSellerPaymentAccepted.ts +0 -35
@@ -13042,15 +13042,38 @@ var PaymentService = /** @class */ (function (_super) {
13042
13042
  };
13043
13043
  PaymentService.prototype.issueTicketThroughFaceToFace = function (params) {
13044
13044
  return __awaiter(this, void 0, void 0, function () {
13045
+ var purpose;
13045
13046
  var _this = this;
13046
13047
  return __generator(this, function (_a) {
13048
+ purpose = params.purpose;
13047
13049
  return [2 /*return*/, this.fetch({
13048
13050
  uri: "/payment/" + factory.service.paymentService.PaymentServiceType.FaceToFace + "/tickets",
13049
13051
  method: 'POST',
13050
13052
  expectedStatusCodes: [http_status_1.CREATED],
13051
- body: params,
13053
+ body: { purpose: purpose },
13052
13054
  qs: {
13053
- purpose: { id: params.purpose.id } // 追加(2024-04-01~)
13055
+ purpose: { id: params.purpose.id }
13056
+ }
13057
+ })
13058
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
13059
+ return [2 /*return*/, response.json()];
13060
+ }); }); })];
13061
+ });
13062
+ });
13063
+ };
13064
+ PaymentService.prototype.issueTicketThroughCreditCard = function (params) {
13065
+ return __awaiter(this, void 0, void 0, function () {
13066
+ var purpose, ticketedPermit;
13067
+ var _this = this;
13068
+ return __generator(this, function (_a) {
13069
+ purpose = params.purpose, ticketedPermit = params.ticketedPermit;
13070
+ return [2 /*return*/, this.fetch({
13071
+ uri: "/payment/" + factory.service.paymentService.PaymentServiceType.CreditCard + "/tickets",
13072
+ method: 'POST',
13073
+ expectedStatusCodes: [http_status_1.CREATED],
13074
+ body: { purpose: purpose, ticketedPermit: ticketedPermit },
13075
+ qs: {
13076
+ purpose: { id: params.purpose.id }
13054
13077
  }
13055
13078
  })
13056
13079
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -20703,6 +20726,9 @@ var PaymentService = /** @class */ (function (_super) {
20703
20726
  });
20704
20727
  });
20705
20728
  };
20729
+ /**
20730
+ * 対面決済によるチケット発行
20731
+ */
20706
20732
  PaymentService.prototype.issueTicketThroughFaceToFace = function (params) {
20707
20733
  return __awaiter(this, void 0, void 0, function () {
20708
20734
  var _a, auth, endpoint, project, seller, disableAutoRetry, retryableStatusCodes, chevrePay, paymentService;
@@ -20728,6 +20754,34 @@ var PaymentService = /** @class */ (function (_super) {
20728
20754
  });
20729
20755
  });
20730
20756
  };
20757
+ /**
20758
+ * CreditCardIF決済によるチケット発行
20759
+ */
20760
+ PaymentService.prototype.issueTicketThroughCreditCard = function (params) {
20761
+ return __awaiter(this, void 0, void 0, function () {
20762
+ var _a, auth, endpoint, project, seller, disableAutoRetry, retryableStatusCodes, chevrePay, paymentService;
20763
+ return __generator(this, function (_b) {
20764
+ switch (_b.label) {
20765
+ case 0:
20766
+ _a = this.options, auth = _a.auth, endpoint = _a.endpoint, project = _a.project, seller = _a.seller, disableAutoRetry = _a.disableAutoRetry, retryableStatusCodes = _a.retryableStatusCodes;
20767
+ return [4 /*yield*/, index_1.loadChevrePay({ auth: auth, endpoint: endpoint, disableAutoRetry: disableAutoRetry })];
20768
+ case 1:
20769
+ chevrePay = _b.sent();
20770
+ return [4 /*yield*/, chevrePay.createPaymentInstance({
20771
+ project: project,
20772
+ seller: { id: (typeof (seller === null || seller === void 0 ? void 0 : seller.id) === 'string') ? seller.id : '' },
20773
+ retryableStatusCodes: __spreadArray(__spreadArray([], (Array.isArray(retryableStatusCodes)) ? retryableStatusCodes : []), [
20774
+ http_status_1.CONFLICT,
20775
+ http_status_1.TOO_MANY_REQUESTS
20776
+ ])
20777
+ })];
20778
+ case 2:
20779
+ paymentService = _b.sent();
20780
+ return [2 /*return*/, paymentService.issueTicketThroughCreditCard(params)];
20781
+ }
20782
+ });
20783
+ });
20784
+ };
20731
20785
  return PaymentService;
20732
20786
  }(service_1.Service));
20733
20787
  exports.PaymentService = PaymentService;
@@ -25211,7 +25265,7 @@ var CategorySetIdentifier;
25211
25265
  */
25212
25266
  CategorySetIdentifier["DistributorType"] = "DistributorType";
25213
25267
  /**
25214
- * メンバーシップタイプ
25268
+ * メンバーシップ区分
25215
25269
  */
25216
25270
  CategorySetIdentifier["MembershipType"] = "MembershipType";
25217
25271
  /**
@@ -30,7 +30,7 @@ async function main() {
30
30
  });
31
31
 
32
32
  const searchSellersResult = await sellerService.search({ limit: 1, $projection: {} });
33
- const seller = searchSellersResult.data[0];
33
+ const seller = searchSellersResult[0];
34
34
 
35
35
  const transactionNumber = `CIN${(new Date()).valueOf()}`;
36
36
  const paymentMethodType = 'MovieTicket';
@@ -30,7 +30,7 @@ async function main() {
30
30
  });
31
31
 
32
32
  const searchSellersResult = await sellerService.search({ limit: 1, $projection: {} });
33
- const seller = searchSellersResult.data[0];
33
+ const seller = searchSellersResult[0];
34
34
 
35
35
  const transactionNumber = `CIN${(new Date()).valueOf()}`;
36
36
  const paymentMethodType = 'PayPay';
@@ -30,7 +30,7 @@ async function main() {
30
30
  });
31
31
 
32
32
  const searchSellersResult = await sellerService.search({ limit: 1, $projection: {} });
33
- const seller = searchSellersResult.data[0];
33
+ const seller = searchSellersResult[0];
34
34
 
35
35
  const transactionNumber = `CIN${(new Date()).valueOf()}`;
36
36
  const paymentMethodType = 'CreditCard';
@@ -30,13 +30,6 @@ async function main() {
30
30
  })).createSellerInstance({
31
31
  project
32
32
  });
33
- const placeOrderService = await (await client.loadChevreTxn({
34
- endpoint: `${<string>process.env.CHEVRE_ENDPOINT}/txn`,
35
- auth: authClient
36
- })).createPlaceOrderTransactionInstance({
37
- project,
38
- seller: { id: '' }
39
- });
40
33
 
41
34
  console.log('finding profile...');
42
35
  // const profile = await personService.getProfile({ personId: 'me' });
@@ -47,12 +40,34 @@ async function main() {
47
40
  branchCode: { $eq: '001' },
48
41
  $projection: {}
49
42
  });
50
- // tslint:disable-next-line:insecure-random
51
- const seller = searchSellersResult.data[Math.floor(searchSellersResult.data.length * Math.random())];
43
+ const seller = searchSellersResult.shift();
52
44
  if (seller === undefined) {
53
45
  throw new Error('No seller');
54
46
  }
55
47
  console.log('ordering from seller...', (<client.factory.multilingualString>seller.name).ja);
48
+ const sellerId = String(seller.id);
49
+
50
+ const placeOrderService = await (await client.loadChevreTxn({
51
+ endpoint: <string>process.env.CHEVRE_ENDPOINT_TXN,
52
+ auth: authClient
53
+ })).createPlaceOrderTransactionInstance({
54
+ project,
55
+ seller: { id: sellerId }
56
+ });
57
+ const offerService = await (await client.loadChevreTxn({
58
+ endpoint: <string>process.env.CHEVRE_ENDPOINT_TXN,
59
+ auth: authClient
60
+ })).createOfferInstance({
61
+ project,
62
+ seller: { id: sellerId }
63
+ });
64
+ const paymentService = await (await client.loadChevrePay({
65
+ endpoint: <string>process.env.CHEVRE_ENDPOINT_PAY,
66
+ auth: authClient
67
+ })).createPaymentInstance({
68
+ project,
69
+ seller: { id: sellerId }
70
+ });
56
71
 
57
72
  console.log('starting transaction...');
58
73
  const transaction = await placeOrderService.start({
@@ -61,24 +76,7 @@ async function main() {
61
76
  {
62
77
  name: 'SampleName',
63
78
  value: 'SampleValue'
64
- },
65
- ...(typeof process.env.LINE_NOTIFY_URL === 'string' && process.env.LINE_NOTIFY_URL.length > 0)
66
- ? [
67
- {
68
- name: 'onOrderPlaced.recipient.url',
69
- value: process.env.LINE_NOTIFY_URL
70
- },
71
- {
72
- name: 'onOrderPlaced.object.customer.identifier',
73
- value: 'onOrderPlaced.object.customer.identifier.value1'
74
- },
75
- {
76
- name: 'onOrderPlaced.object.customer.identifier',
77
- value: 'onOrderPlaced.object.customer.identifier.value2'
78
- }
79
-
80
- ]
81
- : []
79
+ }
82
80
  ]
83
81
  },
84
82
  seller: {
@@ -90,9 +88,55 @@ async function main() {
90
88
  });
91
89
  console.log('transaction started', transaction.id);
92
90
 
93
- // 購入者情報入力時間
94
- // tslint:disable-next-line:no-magic-numbers
95
- await wait(5000);
91
+ await wait(3000);
92
+
93
+ // オファー承認
94
+ await offerService.authorizeEventService({
95
+ object: {
96
+ reservationFor: {
97
+ id: 'blxd1gryb'
98
+ },
99
+ acceptedOffer: [{
100
+ id: '3001', // 0yen offer
101
+ itemOffered: {
102
+ serviceOutput: {
103
+ typeOf: client.factory.reservationType.EventReservation,
104
+ reservedTicket: {
105
+ typeOf: 'Ticket',
106
+ ticketedSeat: {
107
+ typeOf: client.factory.placeType.Seat,
108
+ seatNumber: 'B-3',
109
+ seatSection: 'Default',
110
+ seatRow: ''
111
+ }
112
+ }
113
+ // programMembershipUsed: {
114
+ // ticketToken: 'a1b8a25c-188c-4ba4-8d12-639d3a20dc7d',
115
+ // typeOf: 'Ticket'
116
+ // }
117
+ }
118
+ }
119
+ }]
120
+ },
121
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
122
+ });
123
+ console.log('offer authorized');
124
+
125
+ await wait(3000);
126
+
127
+ // 決済承認
128
+ await paymentService.authorizeAnyPayment({
129
+ object: {
130
+ amount: 0,
131
+ issuedThrough: { id: '' },
132
+ paymentMethod: 'Cash'
133
+ // ticketToken
134
+ },
135
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
136
+ });
137
+ console.log('payment authorized');
138
+
139
+ await wait(3000);
96
140
 
97
141
  const settingProfile: client.factory.person.IProfile = {
98
142
  givenName: 'Taro',
@@ -104,28 +148,7 @@ async function main() {
104
148
  await placeOrderService.setProfile({ id: transaction.id, agent: settingProfile });
105
149
  console.log('customer profile set');
106
150
 
107
- // let i = 0;
108
- // setInterval(
109
- // async () => {
110
- // i += 1;
111
- // try {
112
- // console.log('setting customer profile...');
113
- // await placeOrderService.setProfile({ id: transaction.id, agent: settingProfile });
114
- // console.log('customer profile set');
115
-
116
- // } catch (error) {
117
- // console.error('setting profile failed.', error.message);
118
- // }
119
- // },
120
- // // tslint:disable-next-line:no-magic-numbers
121
- // 500
122
- // );
123
-
124
- // return;
125
-
126
- // 購入情報確認時間
127
- // tslint:disable-next-line:no-magic-numbers
128
- await wait(5000);
151
+ await wait(3000);
129
152
 
130
153
  await placeOrderService.updateObject({
131
154
  id: transaction.id,
@@ -53,7 +53,7 @@ async function main() {
53
53
  $projection: {}
54
54
  });
55
55
  // tslint:disable-next-line:insecure-random
56
- const seller = searchSellersResult.data[Math.floor(searchSellersResult.data.length * Math.random())];
56
+ const seller = searchSellersResult[Math.floor(searchSellersResult.length * Math.random())];
57
57
  if (seller === undefined) {
58
58
  throw new Error('No seller');
59
59
  }
@@ -36,8 +36,7 @@ async function main() {
36
36
  branchCode: { $eq: '001' },
37
37
  $projection: {}
38
38
  });
39
- // tslint:disable-next-line:insecure-random
40
- const seller = searchSellersResult.data[Math.floor(searchSellersResult.data.length * Math.random())];
39
+ const seller = searchSellersResult.shift();
41
40
  if (seller === undefined) {
42
41
  throw new Error('No seller');
43
42
  }
@@ -100,7 +99,7 @@ async function main() {
100
99
  id: 'blxd1gryb'
101
100
  },
102
101
  acceptedOffer: [{
103
- id: 'bkpnwjw1w', // メンバーシップ適用オファーを指定
102
+ id: 'bkpnwjw1w', // メンバーシップ対象オファーを指定
104
103
  itemOffered: {
105
104
  serviceOutput: {
106
105
  typeOf: client.factory.reservationType.EventReservation,
@@ -108,7 +107,7 @@ async function main() {
108
107
  typeOf: 'Ticket',
109
108
  ticketedSeat: {
110
109
  typeOf: client.factory.placeType.Seat,
111
- seatNumber: 'B-4',
110
+ seatNumber: 'B-3',
112
111
  seatSection: 'Default',
113
112
  seatRow: ''
114
113
  }
@@ -129,10 +128,11 @@ async function main() {
129
128
 
130
129
  await wait(3000);
131
130
 
132
- // 決済承認
131
+ // YEN決済承認
133
132
  await paymentService.authorizeAnyPayment({
134
133
  object: {
135
- amount: 999,
134
+ // amount: 999,
135
+ amount: 0,
136
136
  issuedThrough: { id: '' },
137
137
  paymentMethod: 'Cash',
138
138
  ticketToken // チケット指定
@@ -143,6 +143,19 @@ async function main() {
143
143
 
144
144
  await wait(3000);
145
145
 
146
+ // ポイント決済承認
147
+ await paymentService.authorizeAnyPayment({
148
+ object: {
149
+ amount: 999,
150
+ issuedThrough: { id: '' },
151
+ paymentMethod: 'PointCard'
152
+ },
153
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
154
+ });
155
+ console.log('payment authorized');
156
+
157
+ await wait(3000);
158
+
146
159
  const settingProfile: client.factory.person.IProfile = {
147
160
  givenName: profile.givenName,
148
161
  familyName: profile.familyName,
@@ -155,14 +168,22 @@ async function main() {
155
168
 
156
169
  await wait(3000);
157
170
 
158
- console.log('confirming transaction...');
159
- const confirmResult = await placeOrderService.confirm({
160
- id: transaction.id,
161
- sendEmailMessage: true,
162
- expectsMinimalResponse: true
163
- // expectsReservationIds: true
164
- });
165
- console.log('transaction confirmed', confirmResult);
171
+ try {
172
+ console.log('confirming transaction...');
173
+ const confirmResult = await placeOrderService.confirm({
174
+ id: transaction.id,
175
+ sendEmailMessage: true,
176
+ expectsMinimalResponse: true
177
+ // expectsReservationIds: true
178
+ });
179
+ console.log('transaction confirmed', confirmResult);
180
+ } catch (error) {
181
+ console.error(error);
182
+ console.log('canceling transaction...');
183
+ await wait(3000);
184
+ await placeOrderService.cancel({ id: transaction.id });
185
+ console.log('transaction canceled');
186
+ }
166
187
  }
167
188
 
168
189
  async function wait(waitInMilliseconds: number) {
@@ -0,0 +1,74 @@
1
+ // tslint:disable:no-console no-implicit-dependencies no-magic-numbers
2
+ import * as moment from 'moment';
3
+ import * as client from '../../../../lib/index';
4
+
5
+ async function wait(waitInMilliseconds: number) {
6
+ return new Promise((resolve) => setTimeout(resolve, waitInMilliseconds));
7
+ }
8
+
9
+ const USE_FORCE_AUTHORIZE_PAYMENT_ASYNC_GIVE_UP_SECONDS = 10;
10
+ const USE_FORCE_AUTHORIZE_PAYMENT_ASYNC_CHECK_INTERVAL_MS = 1000;
11
+ export function authorizeCreditCardAsyncForcibly(params: {
12
+ object: Pick<
13
+ client.factory.action.authorize.paymentMethod.any.IObjectWithoutDetail,
14
+ 'amount' | 'issuedThrough' | 'paymentMethod' | 'creditCard' | 'method' | 'paymentMethodId' | 'name' | 'additionalProperty' | 'ticketToken'
15
+ >;
16
+ purpose: {
17
+ typeOf: client.factory.transactionType.PlaceOrder;
18
+ id: string;
19
+ };
20
+ }) {
21
+ return async (repos: {
22
+ paymentService: client.cloudPay.service.Payment;
23
+ }): Promise<{ id: string }> => {
24
+ // 決済承認タスク作成
25
+ const authorizeTask = await repos.paymentService.authorizeCreditCardAsync(params);
26
+ const giveUpPayment = moment()
27
+ .add(USE_FORCE_AUTHORIZE_PAYMENT_ASYNC_GIVE_UP_SECONDS, 'seconds');
28
+ let result: { id: string } | undefined;
29
+ let error: { name?: string; message?: string } | undefined;
30
+
31
+ // n秒おきに状態確認
32
+ while (result === undefined && error === undefined) {
33
+ await wait(USE_FORCE_AUTHORIZE_PAYMENT_ASYNC_CHECK_INTERVAL_MS); // n秒待機
34
+
35
+ // タスク作成から一定時間経過すればあきらめる
36
+ if (moment()
37
+ .isAfter(giveUpPayment)) {
38
+ error = new client.factory.errors.GatewayTimeout('action given up');
39
+ break;
40
+ }
41
+
42
+ const authorizeAction = await repos.paymentService.findAuthorizeAction({
43
+ sameAs: { id: authorizeTask.id },
44
+ object: {
45
+ typeOf: client.factory.service.paymentService.PaymentServiceType.CreditCard
46
+ },
47
+ purpose: params.purpose
48
+ });
49
+
50
+ // アクションIDが存在し、CompletedActionStatusであればタスク完了とみなす
51
+ if (typeof authorizeAction.id === 'string') {
52
+ if (authorizeAction.actionStatus === client.factory.actionStatusType.CompletedActionStatus) {
53
+ // ステータス完了であれば決済承認アクションIDを保管
54
+ result = { id: authorizeAction.id };
55
+ break;
56
+ } else {
57
+ // 待機続行
58
+ }
59
+ }
60
+
61
+ // エラーが存在すれば、これ以上待機する価値はなし
62
+ if (authorizeAction.error !== undefined) {
63
+ error = authorizeAction.error;
64
+ break;
65
+ }
66
+ }
67
+
68
+ if (typeof result?.id === 'string') {
69
+ return result;
70
+ }
71
+
72
+ throw error;
73
+ };
74
+ }