@cinerino/sdk 7.0.0-alpha.4 → 7.0.0-alpha.6

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.
@@ -0,0 +1,201 @@
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
+ const project = { id: String(process.env.PROJECT_ID) };
6
+
7
+ const profile = {
8
+ email: <string>process.env.TEST_PROFILE_EMAIL,
9
+ givenName: 'Taro',
10
+ familyName: 'SDK',
11
+ name: 'Taro ☆ SDK',
12
+ telephone: '+819012345678'
13
+ };
14
+
15
+ // export type IAuthorizeReservationAction
16
+ // = client.factory.action.authorize.offer.eventService.IAction<client.factory.service.webAPI.Identifier.Chevre>;
17
+
18
+ // tslint:disable-next-line:max-func-body-length
19
+ async function main() {
20
+ const authClient = await client.auth.ClientCredentials.createInstance({
21
+ domain: <string>process.env.CHEVRE_AUTHORIZE_SERVER_DOMAIN,
22
+ clientId: <string>process.env.CHEVRE_CLIENT_ID,
23
+ clientSecret: <string>process.env.CHEVRE_CLIENT_SECRET,
24
+ scopes: [],
25
+ state: ''
26
+ });
27
+
28
+ const placeOrderService = await (await client.loadChevreTxn({
29
+ endpoint: `${<string>process.env.CHEVRE_ENDPOINT}/txn`,
30
+ auth: authClient
31
+ })).createPlaceOrderTransactionInstance({
32
+ project,
33
+ seller: { id: '' }
34
+ });
35
+ const offerService = await (await client.loadChevreTxncoa({
36
+ endpoint: `${<string>process.env.CHEVRE_ENDPOINT}/txncoa`,
37
+ auth: authClient
38
+ })).createOfferInstance({
39
+ project,
40
+ seller: { id: '' }
41
+ });
42
+
43
+ console.log('starting transaction...');
44
+ const transaction = await placeOrderService.start({
45
+ agent: {},
46
+ seller: {
47
+ id: '5d0abf30ac3fb200198ebb2c'
48
+ },
49
+ object: {
50
+ // passport: { token: passportToken }
51
+ }
52
+ });
53
+ console.log('transaction started', transaction.id);
54
+
55
+ // 購入者情報入力時間
56
+ // tslint:disable-next-line:no-magic-numbers
57
+ await wait(5000);
58
+
59
+ console.log('creating accept task..,');
60
+ const acceptTask = await offerService.acceptOffer({
61
+ object: {
62
+ event: { id: '120162210202405231202250' },
63
+ acceptedOffer: [{
64
+ seatSection: ' ',
65
+ seatNumber: 'b-34',
66
+ ticketInfo: {
67
+ ticketCode: '171',
68
+ mvtkAppPrice: 0,
69
+ ticketCount: 1,
70
+ addGlasses: 0,
71
+ kbnEisyahousiki: '00',
72
+ mvtkNum: '',
73
+ mvtkKbnDenshiken: '00',
74
+ mvtkKbnMaeuriken: '00',
75
+ mvtkKbnKensyu: '00',
76
+ mvtkSalesPrice: 0,
77
+ kbnMgtk: ''
78
+ }
79
+ }],
80
+ appliesToSurfrock: {
81
+ identifier: '',
82
+ serviceOutput: { typeOf: '' }
83
+ }
84
+ },
85
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
86
+ });
87
+ console.log('acceptTask created,', acceptTask);
88
+
89
+ const giveUpPayment = moment()
90
+ .add(10, 'seconds');
91
+ let result: { id: string } | undefined;
92
+ let error: any;
93
+
94
+ // n秒おきに状態確認
95
+ while (result === undefined && error === undefined) {
96
+ // n秒待機
97
+ await new Promise<void>((resolveWait) => {
98
+ setTimeout(
99
+ () => { resolveWait(); },
100
+ 1000
101
+ );
102
+ });
103
+
104
+ // タスク作成から一定時間経過すればあきらめる
105
+ if (moment()
106
+ .isAfter(giveUpPayment)) {
107
+ error = new client.factory.errors.GatewayTimeout('action gaven up');
108
+ break;
109
+ }
110
+
111
+ const acceptAction = await offerService.findAcceptAction({
112
+ sameAs: { id: acceptTask.id },
113
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
114
+ });
115
+ console.log('acceptAction:,', acceptAction);
116
+
117
+ if (typeof acceptAction.id === 'string') {
118
+ if (acceptAction.actionStatus === client.factory.actionStatusType.CompletedActionStatus) {
119
+ // ステータス完了であれば決済承認アクションIDを保管
120
+ result = { id: acceptAction.id };
121
+ break;
122
+ } else {
123
+ // 待機続行
124
+ }
125
+ }
126
+
127
+ // エラーが存在すれば、これ以上待機する価値はなし
128
+ if (acceptAction.error !== undefined) {
129
+ error = acceptAction.error;
130
+ break;
131
+ }
132
+ }
133
+
134
+ if (typeof result?.id === 'string') {
135
+ // no op
136
+ // return result;
137
+ } else {
138
+ throw error;
139
+ }
140
+ console.log('acceptAcion.result:', result);
141
+
142
+ // 購入者情報入力時間
143
+ // tslint:disable-next-line:no-magic-numbers
144
+ await wait(5000);
145
+
146
+ console.log('authorizing by acceptAction...', result.id);
147
+
148
+ const settingProfile: client.factory.person.IProfile = {
149
+ givenName: profile.givenName,
150
+ familyName: profile.familyName,
151
+ telephone: profile.telephone,
152
+ email: profile.email
153
+ };
154
+ console.log('setting customer profile...');
155
+ await placeOrderService.setProfile({ id: transaction.id, agent: settingProfile });
156
+ console.log('customer profile set');
157
+
158
+ // 購入情報確認時間
159
+ // tslint:disable-next-line:no-magic-numbers
160
+ await wait(5000);
161
+
162
+ await placeOrderService.updateObject({
163
+ id: transaction.id,
164
+ object: { name: 'order from samples' }
165
+ });
166
+
167
+ // 取引を中止する場合はコチラ↓
168
+ // console.log('取引を中止します...');
169
+ // await placeOrderService.cancel({ id: transaction.id });
170
+ // console.log('取引を中止しました。');
171
+
172
+ console.log('confirming transaction...');
173
+ await new Promise<void>(async (resolve, reject) => {
174
+ setTimeout(
175
+ () => {
176
+ reject(new Error('confirming process took too long'));
177
+ },
178
+ 5000
179
+ );
180
+ const confirmResult = await placeOrderService.confirm({
181
+ id: transaction.id,
182
+ sendEmailMessage: true,
183
+ expectsMinimalResponse: true
184
+ // expectsReservationIds: true
185
+ });
186
+ const order = confirmResult.order;
187
+ console.log('transaction confirmed', confirmResult);
188
+ console.log('transaction confirmed', order.orderNumber);
189
+ resolve();
190
+ });
191
+ }
192
+
193
+ async function wait(waitInMilliseconds: number) {
194
+ return new Promise((resolve) => setTimeout(resolve, waitInMilliseconds));
195
+ }
196
+
197
+ main()
198
+ .then(() => {
199
+ console.log('success!');
200
+ })
201
+ .catch(console.error);
@@ -14,6 +14,23 @@ export interface IAuthorizeResult {
14
14
  export interface ICheckMovieTicketResult {
15
15
  purchaseNumberAuthResult: factory.action.check.paymentMethod.movieTicket.IPurchaseNumberAuthResult;
16
16
  }
17
+ export interface IMinimizedCheckMovieTicketResult {
18
+ purchaseNumberAuthResult: Omit<ICheckMovieTicketResult['purchaseNumberAuthResult'], 'knyknrNoInfoOut'> & {
19
+ knyknrNoInfoOut: Omit<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberInfo, 'ykknInfo' | 'mkknInfo'>[] | null;
20
+ };
21
+ }
22
+ export declare type IMovieTicketYkknInfo = factory.action.check.paymentMethod.movieTicket.IYkknInfo & {
23
+ /**
24
+ * 購入管理番号
25
+ */
26
+ knyknrNo: string;
27
+ };
28
+ export declare type IMovieTicketMkknInfo = factory.action.check.paymentMethod.movieTicket.IMkknInfo & {
29
+ /**
30
+ * 購入管理番号
31
+ */
32
+ knyknrNo: string;
33
+ };
17
34
  export declare type IAuthorizeAnyPaymentObject = Pick<factory.action.authorize.paymentMethod.any.IObjectWithoutDetail, 'amount' | 'issuedThrough' | 'paymentMethod' | 'name' | 'additionalProperty'>;
18
35
  export declare type IAuthorizeCreditCardObject = Pick<factory.action.authorize.paymentMethod.any.IObjectWithoutDetail, 'amount' | 'issuedThrough' | 'paymentMethod' | 'creditCard' | 'method' | 'paymentMethodId' | 'name' | 'additionalProperty'>;
19
36
  export declare type IAuthorizeMovieTicketObject = Pick<factory.action.authorize.paymentMethod.any.IObjectWithoutDetail, 'issuedThrough' | 'paymentMethod' | 'movieTickets' | 'name' | 'additionalProperty'>;
@@ -1,6 +1,6 @@
1
1
  import * as factory from '../factory';
2
2
  import { Service } from '../service';
3
- import { IAuthorizeAnyPaymentObject, IAuthorizeCreditCardObject, IAuthorizeMovieTicketObject, IAuthorizePaymentCardObject, IAuthorizeResult, ICheckMovieTicketResult, IFindAuthorizeActionResult, IPublishPaymentUrlObject, IPublishPaymentUrlResult, IPurpose } from './payment/factory';
3
+ import { IAuthorizeAnyPaymentObject, IAuthorizeCreditCardObject, IAuthorizeMovieTicketObject, IAuthorizePaymentCardObject, IAuthorizeResult, ICheckMovieTicketResult, IFindAuthorizeActionResult, IMinimizedCheckMovieTicketResult, IMovieTicketMkknInfo, IMovieTicketYkknInfo, IPublishPaymentUrlObject, IPublishPaymentUrlResult, IPurpose } from './payment/factory';
4
4
  /**
5
5
  * 決済サービス
6
6
  */
@@ -125,7 +125,12 @@ export declare class PaymentService extends Service {
125
125
  id: string;
126
126
  };
127
127
  purpose: IPurpose;
128
+ minimize: boolean;
128
129
  }): Promise<{
130
+ /**
131
+ * 認証アクションID
132
+ */
133
+ id?: string;
129
134
  /**
130
135
  * アクションステータス
131
136
  */
@@ -137,8 +142,38 @@ export declare class PaymentService extends Service {
137
142
  name?: string;
138
143
  message?: string;
139
144
  };
140
- result?: Pick<ICheckMovieTicketResult, 'purchaseNumberAuthResult'>;
145
+ result?: IMinimizedCheckMovieTicketResult;
141
146
  }>;
147
+ /**
148
+ * 決済カード認証アクションから有効券を検索する
149
+ */
150
+ searchYkknInfoByCheckMovieTicketAction(params: {
151
+ /**
152
+ * max: 20
153
+ */
154
+ limit: number;
155
+ page: number;
156
+ /**
157
+ * 認証アクションID
158
+ */
159
+ id: string;
160
+ purpose: IPurpose;
161
+ }): Promise<IMovieTicketYkknInfo[]>;
162
+ /**
163
+ * 決済カード認証アクションから無効券を検索する
164
+ */
165
+ searchMkknInfoByCheckMovieTicketAction(params: {
166
+ /**
167
+ * max: 20
168
+ */
169
+ limit: number;
170
+ page: number;
171
+ /**
172
+ * 認証アクションID
173
+ */
174
+ id: string;
175
+ purpose: IPurpose;
176
+ }): Promise<IMovieTicketMkknInfo[]>;
142
177
  /**
143
178
  * 決済採用アクション検索
144
179
  */
@@ -340,15 +340,60 @@ var PaymentService = /** @class */ (function (_super) {
340
340
  */
341
341
  PaymentService.prototype.findCheckMovieTicketAction = function (params) {
342
342
  return __awaiter(this, void 0, void 0, function () {
343
- var sameAs, purpose;
343
+ var sameAs, purpose, minimize;
344
344
  var _this = this;
345
345
  return __generator(this, function (_a) {
346
- sameAs = params.sameAs, purpose = params.purpose;
346
+ sameAs = params.sameAs, purpose = params.purpose, minimize = params.minimize;
347
347
  return [2 /*return*/, this.fetch({
348
348
  uri: "/payment/" + factory.service.paymentService.PaymentServiceType.MovieTicket + "/check/" + sameAs.id,
349
349
  method: 'GET',
350
350
  expectedStatusCodes: [http_status_1.OK],
351
- qs: { purpose: { id: purpose.id } }
351
+ qs: {
352
+ purpose: { id: purpose.id },
353
+ minimize: minimize === true
354
+ }
355
+ })
356
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
357
+ return [2 /*return*/, response.json()];
358
+ }); }); })];
359
+ });
360
+ });
361
+ };
362
+ /**
363
+ * 決済カード認証アクションから有効券を検索する
364
+ */
365
+ PaymentService.prototype.searchYkknInfoByCheckMovieTicketAction = function (params) {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ var id, purpose, limit, page;
368
+ var _this = this;
369
+ return __generator(this, function (_a) {
370
+ id = params.id, purpose = params.purpose, limit = params.limit, page = params.page;
371
+ return [2 /*return*/, this.fetch({
372
+ uri: "/payment/" + factory.service.paymentService.PaymentServiceType.MovieTicket + "/check/" + id + "/result/ykknInfo",
373
+ method: 'GET',
374
+ expectedStatusCodes: [http_status_1.OK],
375
+ qs: { purpose: purpose, limit: limit, page: page }
376
+ })
377
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
378
+ return [2 /*return*/, response.json()];
379
+ }); }); })];
380
+ });
381
+ });
382
+ };
383
+ /**
384
+ * 決済カード認証アクションから無効券を検索する
385
+ */
386
+ PaymentService.prototype.searchMkknInfoByCheckMovieTicketAction = function (params) {
387
+ return __awaiter(this, void 0, void 0, function () {
388
+ var id, purpose, limit, page;
389
+ var _this = this;
390
+ return __generator(this, function (_a) {
391
+ id = params.id, purpose = params.purpose, limit = params.limit, page = params.page;
392
+ return [2 /*return*/, this.fetch({
393
+ uri: "/payment/" + factory.service.paymentService.PaymentServiceType.MovieTicket + "/check/" + id + "/result/mkknInfo",
394
+ method: 'GET',
395
+ expectedStatusCodes: [http_status_1.OK],
396
+ qs: { purpose: purpose, limit: limit, page: page }
352
397
  })
353
398
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
354
399
  return [2 /*return*/, response.json()];
@@ -0,0 +1,162 @@
1
+ import * as factory from '../factory';
2
+ import { Service } from '../service';
3
+ import { IAuthorizeCOAEventServiceResult } from '../chevreTxn/transaction/placeOrder/factory';
4
+ export interface IPurpose {
5
+ typeOf: factory.transactionType;
6
+ id: string;
7
+ }
8
+ export declare enum FlgMember {
9
+ /**
10
+ * 非会員
11
+ */
12
+ NonMember = "0",
13
+ /**
14
+ * 会員
15
+ */
16
+ Member = "1"
17
+ }
18
+ export interface ICOAPointOffer {
19
+ /**
20
+ * オファーID
21
+ */
22
+ id: string;
23
+ /**
24
+ * オファーコード
25
+ */
26
+ identifier: string;
27
+ /**
28
+ * チケットコード
29
+ */
30
+ ticketCode: string;
31
+ /**
32
+ * チケット名
33
+ */
34
+ ticketName: string;
35
+ /**
36
+ * チケット名(カナ)
37
+ */
38
+ ticketNameKana: string;
39
+ /**
40
+ * チケット名(英)
41
+ */
42
+ ticketNameEng: string;
43
+ /**
44
+ * ポイント購入の場合の消費ポイント
45
+ */
46
+ usePoint: number;
47
+ /**
48
+ * 会員用フラグ
49
+ */
50
+ flgMember?: FlgMember;
51
+ }
52
+ interface IAppliesToSurfrock {
53
+ identifier: string;
54
+ serviceOutput: {
55
+ typeOf: string;
56
+ };
57
+ }
58
+ /**
59
+ * オファーサービス
60
+ */
61
+ export declare class OfferService extends Service {
62
+ acceptOffer(params: {
63
+ object: {
64
+ /**
65
+ * イベント
66
+ */
67
+ event: {
68
+ id: string;
69
+ };
70
+ /**
71
+ * オファー
72
+ */
73
+ acceptedOffer: factory.action.authorize.offer.eventService.IAcceptedOfferWithoutDetail4COA[];
74
+ /**
75
+ * 会員オファーの場合の適用MovieTicketを指定する
76
+ */
77
+ appliesToSurfrock?: IAppliesToSurfrock;
78
+ };
79
+ purpose: factory.action.authorize.offer.eventService.IPurpose;
80
+ }): Promise<{
81
+ /**
82
+ * task id
83
+ */
84
+ id: string;
85
+ }>;
86
+ findAcceptAction(params: {
87
+ sameAs: {
88
+ id: string;
89
+ };
90
+ purpose: IPurpose;
91
+ }): Promise<{
92
+ /**
93
+ * 採用アクションID
94
+ */
95
+ id?: string;
96
+ /**
97
+ * アクションステータス
98
+ */
99
+ actionStatus: factory.actionStatusType;
100
+ /**
101
+ * エラー
102
+ */
103
+ error?: {
104
+ name?: string;
105
+ message?: string;
106
+ };
107
+ }>;
108
+ /**
109
+ * 興行オファー承認
110
+ */
111
+ authorizeEventServiceByCOA(params: {
112
+ acceptAction: {
113
+ /**
114
+ * 採用アクションID
115
+ */
116
+ id: string;
117
+ };
118
+ purpose: factory.action.authorize.offer.eventService.IPurpose;
119
+ }): Promise<IAuthorizeCOAEventServiceResult>;
120
+ /**
121
+ * 興行オファー承認取消
122
+ */
123
+ voidAuthorizationByCOA(params: {
124
+ /**
125
+ * 承認アクションID
126
+ */
127
+ id: string;
128
+ /**
129
+ * token
130
+ */
131
+ purpose: string;
132
+ purposeRaw: string;
133
+ }): Promise<{
134
+ theaterCode?: string;
135
+ dateJouei?: string;
136
+ titleCode?: string;
137
+ titleBranchNum?: string;
138
+ timeBegin?: string;
139
+ tmpReserveNum?: string;
140
+ }>;
141
+ /**
142
+ * 興行オファー承認変更
143
+ */
144
+ updateEventServiceByCOA(params: {
145
+ /**
146
+ * 承認アクションID
147
+ */
148
+ id: string;
149
+ object: {
150
+ acceptedOffer: factory.action.authorize.offer.eventService.IAcceptedOfferBeforeAuthorize4COA[];
151
+ event: {
152
+ id: string;
153
+ };
154
+ };
155
+ /**
156
+ * token
157
+ */
158
+ purpose: string;
159
+ purposeRaw: string;
160
+ }): Promise<IAuthorizeCOAEventServiceResult>;
161
+ }
162
+ export {};