@cinerino/sdk 5.9.0-alpha.2 → 5.9.0-alpha.3

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,157 @@
1
+ // tslint:disable:no-console no-implicit-dependencies no-magic-numbers
2
+ import * as client from '../../../../lib/index';
3
+ import * as auth from '../../auth/authAsAdmin';
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
+ // tslint:disable-next-line:max-func-body-length
16
+ async function main() {
17
+ const authClient = await auth.login();
18
+ await authClient.refreshAccessToken();
19
+ const loginTicket = authClient.verifyIdToken({});
20
+ console.log('username is', loginTicket.getUsername());
21
+
22
+ const sellerService = await (await client.loadChevre({
23
+ endpoint: <string>process.env.CHEVRE_ENDPOINT,
24
+ auth: authClient
25
+ })).createSellerInstance({
26
+ project
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.loadChevreTxn({
36
+ endpoint: <string>process.env.CHEVRE_ENDPOINT_TXN,
37
+ auth: authClient
38
+ })).createOfferInstance({
39
+ project,
40
+ seller: { id: '' }
41
+ });
42
+ const paymentService = await (await client.loadChevreTxn({
43
+ endpoint: <string>process.env.CHEVRE_ENDPOINT_TXN,
44
+ auth: authClient
45
+ })).createPaymentInstance({
46
+ project,
47
+ seller: { id: '' }
48
+ });
49
+
50
+ // 販売劇場検索
51
+ const searchSellersResult = await sellerService.search({
52
+ branchCode: { $eq: '001' },
53
+ $projection: {}
54
+ });
55
+ // tslint:disable-next-line:insecure-random
56
+ const seller = searchSellersResult.data[Math.floor(searchSellersResult.data.length * Math.random())];
57
+ if (seller === undefined) {
58
+ throw new Error('No seller');
59
+ }
60
+ console.log('ordering from seller...', (<client.factory.multilingualString>seller.name).ja);
61
+
62
+ console.log('starting transaction...');
63
+ const transaction = await placeOrderService.start({
64
+ agent: {
65
+ identifier: [
66
+ {
67
+ name: 'SampleName',
68
+ value: 'SampleValue'
69
+ }
70
+ ]
71
+ },
72
+ seller: {
73
+ id: String(seller.id)
74
+ },
75
+ object: {
76
+ // passport: { token: passportToken }
77
+ }
78
+ });
79
+ console.log('transaction started', transaction.id);
80
+
81
+ await wait(3000);
82
+
83
+ // オファー承認
84
+ await offerService.authorizeProduct({
85
+ object: [{
86
+ typeOf: client.factory.offerType.Offer,
87
+ id: '7iri85wk5ggf685',
88
+ itemOffered: {
89
+ id: '5fadf737c679f7000a3c85b6',
90
+ // pointAward?: IAcceptedPointAward;
91
+ serviceOutput: {
92
+ accessCode: '1234',
93
+ typeOf: client.factory.permit.PermitType.Permit,
94
+ project: { id: project.id, typeOf: client.factory.organizationType.Project },
95
+ name: 'membership from samples'
96
+ }
97
+ }
98
+ }],
99
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
100
+ });
101
+ console.log('offer authorized');
102
+
103
+ await wait(3000);
104
+
105
+ // 決済承認
106
+ await paymentService.authorizeAnyPayment({
107
+ object: {
108
+ // additionalProperty
109
+ amount: 10,
110
+ issuedThrough: { id: '' },
111
+ paymentMethod: 'Cash',
112
+ typeOf: client.factory.action.authorize.paymentMethod.any.ResultType.Payment
113
+
114
+ },
115
+ purpose: { id: transaction.id, typeOf: client.factory.transactionType.PlaceOrder }
116
+ });
117
+ console.log('payment authorized');
118
+
119
+ await wait(3000);
120
+
121
+ console.log('setting customer profile...');
122
+ await placeOrderService.setProfile({ id: transaction.id, agent: profile });
123
+ console.log('customer profile set');
124
+
125
+ // 購入情報確認時間
126
+ // tslint:disable-next-line:no-magic-numbers
127
+ await wait(3000);
128
+
129
+ await placeOrderService.updateObject({
130
+ id: transaction.id,
131
+ object: { name: 'order from samples' }
132
+ });
133
+
134
+ // 取引を中止する場合はコチラ↓
135
+ // console.log('取引を中止します...');
136
+ // await placeOrderService.cancel({ id: transaction.id });
137
+ // console.log('取引を中止しました。');
138
+
139
+ console.log('confirming transaction...');
140
+ const confirmResult = await placeOrderService.confirm({
141
+ id: transaction.id,
142
+ sendEmailMessage: true,
143
+ expectsMinimalResponse: true
144
+ // expectsReservationIds: true
145
+ });
146
+ console.log('transaction confirmed', confirmResult);
147
+ }
148
+
149
+ async function wait(waitInMilliseconds: number) {
150
+ return new Promise((resolve) => setTimeout(resolve, waitInMilliseconds));
151
+ }
152
+
153
+ main()
154
+ .then(() => {
155
+ console.log('success!');
156
+ })
157
+ .catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cinerino/sdk",
3
- "version": "5.9.0-alpha.2",
3
+ "version": "5.9.0-alpha.3",
4
4
  "description": "Cinerino SDK",
5
5
  "main": "./lib/index.js",
6
6
  "browser": {
@@ -96,7 +96,7 @@
96
96
  "watchify": "^3.11.1"
97
97
  },
98
98
  "dependencies": {
99
- "@chevre/factory": "4.352.0-alpha.12",
99
+ "@chevre/factory": "4.352.0-alpha.18",
100
100
  "debug": "^3.2.6",
101
101
  "http-status": "^1.4.2",
102
102
  "idtoken-verifier": "^2.0.3",