@cinerino/sdk 3.130.0-alpha.0 → 3.130.0-alpha.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cinerino/sdk",
3
- "version": "3.130.0-alpha.0",
3
+ "version": "3.130.0-alpha.2",
4
4
  "description": "Cinerino SDK",
5
5
  "main": "./lib/index.js",
6
6
  "browser": {
@@ -97,7 +97,7 @@
97
97
  "watchify": "^3.11.1"
98
98
  },
99
99
  "dependencies": {
100
- "@cinerino/api-abstract-client": "3.130.0-alpha.0",
100
+ "@cinerino/api-abstract-client": "3.130.0-alpha.2",
101
101
  "debug": "^3.2.6",
102
102
  "http-status": "^1.4.2",
103
103
  "idtoken-verifier": "^2.0.3",
@@ -1,186 +0,0 @@
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
- import { auth } from '../auth/clientCredentials';
5
- // import * as auth from '../authAsAdmin';
6
-
7
- const projectId = 'cinerino';
8
-
9
- const profile = {
10
- email: <string>process.env.TEST_PROFILE_EMAIL,
11
- givenName: 'Taro',
12
- familyName: 'SDK',
13
- name: 'Taro ☆ SDK',
14
- telephone: '+819012345678'
15
- };
16
-
17
- const offerService = new client.service.Offer({
18
- endpoint: <string>process.env.API_ENDPOINT,
19
- auth,
20
- project: { id: projectId }
21
- });
22
- const sellerService = new client.service.Seller({
23
- endpoint: <string>process.env.API_ENDPOINT,
24
- auth,
25
- project: { id: projectId }
26
- });
27
- const placeOrderService = new client.service.txn.PlaceOrder({
28
- endpoint: <string>process.env.API_ENDPOINT,
29
- auth,
30
- project: { id: projectId }
31
- });
32
- const paymentService = new client.service.Payment({
33
- endpoint: <string>process.env.API_ENDPOINT,
34
- auth,
35
- project: { id: projectId }
36
- });
37
-
38
- const productService = new client.service.Product({
39
- endpoint: <string>process.env.API_ENDPOINT,
40
- auth,
41
- project: { id: projectId }
42
- });
43
-
44
- // tslint:disable-next-line:max-func-body-length
45
- async function main() {
46
- // 取引に使用するクレジットカード
47
- const creditCard = {
48
- cardNo: '4111111111111111',
49
- expire: '2412',
50
- holderName: 'AA BB'
51
- };
52
-
53
- // プロダクト検索
54
- const { data } = await productService.search({
55
- typeOf: { $eq: 'PaymentCard' }
56
- // typeOf: { $eq: 'MembershipService' }
57
- });
58
- const product = <client.factory.product.IProduct>data.shift();
59
- console.log('ordering product...', (<client.factory.multilingualString>product.name).ja);
60
-
61
- // 販売者検索
62
- const searchSellersResult = await sellerService.search({});
63
- // tslint:disable-next-line:insecure-random
64
- const seller = searchSellersResult.data[Math.floor(searchSellersResult.data.length * Math.random())];
65
- if (seller === undefined) {
66
- throw new Error('No seller');
67
- }
68
- console.log('ordering from seller...', (<client.factory.multilingualString>seller.name).ja);
69
-
70
- // オファー検索
71
- const availableOffers = await productService.searchOffers({
72
- itemOffered: { id: String(product.id) },
73
- seller: { id: String(seller.id) }
74
- });
75
- console.log(availableOffers.length, 'offers available');
76
- const acceptedOffer = availableOffers[0];
77
- console.log('offer selected', (<client.factory.multilingualString>acceptedOffer.name).ja);
78
-
79
- console.log('starting transaction...');
80
- const transaction = await placeOrderService.start({
81
- expires: moment()
82
- .add(1, 'minutes')
83
- .toDate(),
84
- agent: {},
85
- seller: {
86
- typeOf: seller.typeOf,
87
- id: String(seller.id)
88
- },
89
- object: {
90
- // passport: { token: passportToken }
91
- }
92
- });
93
- console.log('transaction started', transaction.id);
94
-
95
- const accessCode = profile.telephone.slice(-4);
96
-
97
- const paymentCardAuthorization = await offerService.authorizeProduct({
98
- object: [{
99
- // project: product.project,
100
- typeOf: client.factory.offerType.Offer,
101
- id: String(acceptedOffer.id),
102
- itemOffered: {
103
- // project: product.project,
104
- // typeOf: product.typeOf,
105
- id: product.id,
106
- serviceOutput: {
107
- project: product.project,
108
- typeOf: client.factory.permit.PermitType.Permit,
109
- accessCode: accessCode,
110
- name: 'サンプルプリペイドカード',
111
- additionalProperty: [{ name: 'sampleName', value: 'sampleValue' }]
112
- }
113
- }
114
- // priceCurrency: client.factory.priceCurrency.JPY,
115
- // seller: { id: seller.id, typeOf: seller.typeOf, project: seller.project }
116
- }],
117
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
118
- });
119
- console.log('paymentCard authorized. id:', paymentCardAuthorization.id);
120
-
121
- if (Number(acceptedOffer.priceSpecification?.price) > 0) {
122
- // クレジットカード決済承認
123
- console.log('authorizing credit card payment...');
124
- const creditCardPaymentAuth = await paymentService.authorizeCreditCard({
125
- object: {
126
- typeOf: client.factory.action.authorize.paymentMethod.any.ResultType.Payment,
127
- amount: Number(acceptedOffer.priceSpecification.price),
128
- paymentMethod: 'CreditCard',
129
- method: '1',
130
- creditCard: creditCard,
131
- issuedThrough: { id: 'xxx' }
132
- },
133
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
134
- });
135
- console.log('credit card payment authorized', creditCardPaymentAuth.id);
136
- }
137
-
138
- await wait(5000);
139
-
140
- console.log('setting customer profile...');
141
- await placeOrderService.setProfile({
142
- id: transaction.id,
143
- agent: profile
144
- });
145
- console.log('customer profile set');
146
-
147
- await wait(5000);
148
-
149
- console.log('confirming transaction...');
150
- const email = {
151
- sender: {
152
- name: `♥ ${(<client.factory.multilingualString>seller.name).ja} ♥`
153
- },
154
- about: `♥♥♥ ${profile.name}さんへプリペイドカード発行のお知らせ ♥♥♥`
155
- };
156
-
157
- const result = await placeOrderService.confirm({
158
- id: transaction.id,
159
- potentialActions: {
160
- order: {
161
- potentialActions: {
162
- sendOrder: {
163
- potentialActions: {
164
- sendEmailMessage: [
165
- {
166
- object: email
167
- }
168
- ]
169
- }
170
- }
171
- }
172
- }
173
- }
174
- });
175
- console.log('transaction confirmed', result.order.orderNumber);
176
- }
177
-
178
- async function wait(waitInMilliseconds: number) {
179
- return new Promise((resolve) => setTimeout(resolve, waitInMilliseconds));
180
- }
181
-
182
- main()
183
- .then(() => {
184
- console.log('success!');
185
- })
186
- .catch(console.error);