pluspay-a2a-react-native 0.1.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.
- package/LICENSE +20 -0
- package/PluspayA2aReactNative.podspec +20 -0
- package/README.md +349 -0
- package/android/build.gradle +67 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/com/pluspaya2areactnative/PluspayA2aReactNativeModule.kt +115 -0
- package/android/src/main/java/com/pluspaya2areactnative/PluspayA2aReactNativePackage.kt +31 -0
- package/ios/PluspayA2aReactNative.h +5 -0
- package/ios/PluspayA2aReactNative.mm +37 -0
- package/lib/module/NativePluspayA2aReactNative.js +14 -0
- package/lib/module/NativePluspayA2aReactNative.js.map +1 -0
- package/lib/module/client.js +112 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/enums.js +190 -0
- package/lib/module/models/enums.js.map +1 -0
- package/lib/module/models/exceptions.js +19 -0
- package/lib/module/models/exceptions.js.map +1 -0
- package/lib/module/models/requests.js +197 -0
- package/lib/module/models/requests.js.map +1 -0
- package/lib/module/models/responses.js +2 -0
- package/lib/module/models/responses.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativePluspayA2aReactNative.d.ts +25 -0
- package/lib/typescript/src/NativePluspayA2aReactNative.d.ts.map +1 -0
- package/lib/typescript/src/client.d.ts +50 -0
- package/lib/typescript/src/client.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/models/enums.d.ts +169 -0
- package/lib/typescript/src/models/enums.d.ts.map +1 -0
- package/lib/typescript/src/models/exceptions.d.ts +10 -0
- package/lib/typescript/src/models/exceptions.d.ts.map +1 -0
- package/lib/typescript/src/models/requests.d.ts +128 -0
- package/lib/typescript/src/models/requests.d.ts.map +1 -0
- package/lib/typescript/src/models/responses.d.ts +51 -0
- package/lib/typescript/src/models/responses.d.ts.map +1 -0
- package/package.json +127 -0
- package/src/NativePluspayA2aReactNative.ts +27 -0
- package/src/client.ts +137 -0
- package/src/index.tsx +5 -0
- package/src/models/enums.ts +186 -0
- package/src/models/exceptions.ts +19 -0
- package/src/models/requests.ts +302 -0
- package/src/models/responses.ts +56 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import Native from './NativePluspayA2aReactNative';
|
|
2
|
+
import { PPA2AException } from './models/exceptions';
|
|
3
|
+
import type { PPRequest } from './models/requests';
|
|
4
|
+
import type {
|
|
5
|
+
PPEodResponse,
|
|
6
|
+
PPMultiPaymentResponse,
|
|
7
|
+
PPOrderPaymentResponse,
|
|
8
|
+
PPParametersResponse,
|
|
9
|
+
PPStartPaymentResponse,
|
|
10
|
+
} from './models/responses';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Main client for PlusPay POS+ App2App (A2A) integration (Android only).
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```ts
|
|
17
|
+
* const pp = new PPA2AClient();
|
|
18
|
+
* await pp.initialize();
|
|
19
|
+
* try {
|
|
20
|
+
* const res = await pp.startPayment(
|
|
21
|
+
* PPStartPaymentRequestModel.toRequest({
|
|
22
|
+
* orderCode: 'ORD001',
|
|
23
|
+
* totalAmount: 100,
|
|
24
|
+
* paymentType: PPPaymentType.POS,
|
|
25
|
+
* paymentMethod: PPPaymentMethod.CC,
|
|
26
|
+
* }),
|
|
27
|
+
* );
|
|
28
|
+
* } catch (e) {
|
|
29
|
+
* if (e instanceof PPA2AException) console.log(e.errorCode, e.message);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class PPA2AClient {
|
|
34
|
+
private initialized = false;
|
|
35
|
+
packageName?: string;
|
|
36
|
+
activityName?: string;
|
|
37
|
+
|
|
38
|
+
/** Must be called once before any request. Registers the result receiver. */
|
|
39
|
+
async initialize(): Promise<void> {
|
|
40
|
+
if (this.initialized) return;
|
|
41
|
+
try {
|
|
42
|
+
const infoStr = await Native.initialize();
|
|
43
|
+
const info = infoStr ? JSON.parse(infoStr) : {};
|
|
44
|
+
this.packageName = info.packageName;
|
|
45
|
+
this.activityName = info.activityName;
|
|
46
|
+
this.initialized = true;
|
|
47
|
+
} catch (e: any) {
|
|
48
|
+
throw new PPA2AException(
|
|
49
|
+
e?.code ?? 'INIT_ERROR',
|
|
50
|
+
e?.message ?? String(e)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private async send(request: PPRequest): Promise<any> {
|
|
56
|
+
if (!this.initialized) {
|
|
57
|
+
throw new PPA2AException(
|
|
58
|
+
'NOT_INITIALIZED',
|
|
59
|
+
'PPA2AClient.initialize() must be called first.'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let responseStr: string;
|
|
64
|
+
try {
|
|
65
|
+
responseStr = await Native.sendRequest(JSON.stringify(request));
|
|
66
|
+
} catch (e: any) {
|
|
67
|
+
throw new PPA2AException(
|
|
68
|
+
e?.code ?? 'LAUNCH_INTENT_ERROR',
|
|
69
|
+
e?.message ?? String(e)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let response: any;
|
|
74
|
+
try {
|
|
75
|
+
response = responseStr ? JSON.parse(responseStr) : {};
|
|
76
|
+
} catch (_) {
|
|
77
|
+
throw new PPA2AException('PP-A2A-PARSE', 'Failed to parse response JSON');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (response?.error_code) {
|
|
81
|
+
throw new PPA2AException(
|
|
82
|
+
response.error_code,
|
|
83
|
+
response.error_message ?? 'Unknown error'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return response;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Start a payment on POS+. */
|
|
90
|
+
startPayment(request: PPRequest): Promise<PPStartPaymentResponse> {
|
|
91
|
+
return this.send(request);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Cancel a payment on POS+. */
|
|
95
|
+
cancelPayment(request: PPRequest): Promise<PPStartPaymentResponse> {
|
|
96
|
+
return this.send(request);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Start an EFT POS payment. */
|
|
100
|
+
startEftPayment(request: PPRequest): Promise<PPStartPaymentResponse> {
|
|
101
|
+
return this.send(request);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Cancel an EFT POS payment. */
|
|
105
|
+
cancelEftPayment(request: PPRequest): Promise<PPStartPaymentResponse> {
|
|
106
|
+
return this.send(request);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Start an order payment flow on POS+. */
|
|
110
|
+
startOrderPayment(request: PPRequest): Promise<PPOrderPaymentResponse> {
|
|
111
|
+
return this.send(request);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Start a multi payment flow on POS+. */
|
|
115
|
+
startMultiPayment(request: PPRequest): Promise<PPMultiPaymentResponse> {
|
|
116
|
+
return this.send(request);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Trigger end-of-day (EOD) on POS+. */
|
|
120
|
+
triggerEod(request: PPRequest): Promise<PPEodResponse> {
|
|
121
|
+
return this.send(request);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Trigger parameter update on POS+. */
|
|
125
|
+
triggerParameters(request: PPRequest): Promise<PPParametersResponse> {
|
|
126
|
+
return this.send(request);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Stop listening and clean up native resources. */
|
|
130
|
+
async dispose(): Promise<void> {
|
|
131
|
+
try {
|
|
132
|
+
await Native.dispose();
|
|
133
|
+
} finally {
|
|
134
|
+
this.initialized = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enums for the POS+ A2A contract. Values are serialized by their constant
|
|
3
|
+
* name (e.g. `PPPaymentType.POS` -> `"POS"`); POS+ uses snake_case only for
|
|
4
|
+
* field names, not for enum values.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export enum PPTransactionType {
|
|
8
|
+
POST_PAYMENT_START = 'POST_PAYMENT_START',
|
|
9
|
+
POST_PAYMENT_CANCEL = 'POST_PAYMENT_CANCEL',
|
|
10
|
+
POST_EFTPOS = 'POST_EFTPOS',
|
|
11
|
+
POST_EFTPOS_CANCEL = 'POST_EFTPOS_CANCEL',
|
|
12
|
+
ORDER_PAYMENT = 'ORDER_PAYMENT',
|
|
13
|
+
EOD = 'EOD',
|
|
14
|
+
PARAMETERS = 'PARAMETERS',
|
|
15
|
+
ORDER_MULTI_PAYMENT = 'ORDER_MULTI_PAYMENT',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum PPPaymentType {
|
|
19
|
+
POS = 'POS',
|
|
20
|
+
PAYCELL = 'PAYCELL',
|
|
21
|
+
HEPSIPAY = 'HEPSIPAY',
|
|
22
|
+
ISTANBULCARD = 'ISTANBULCARD',
|
|
23
|
+
CASH = 'CASH',
|
|
24
|
+
ONLINE = 'ONLINE',
|
|
25
|
+
BANK_TRANSFER = 'BANK_TRANSFER',
|
|
26
|
+
GASTROPAY = 'GASTROPAY',
|
|
27
|
+
CIO_CARD = 'CIO_CARD',
|
|
28
|
+
IWALLET = 'IWALLET',
|
|
29
|
+
PAYE = 'PAYE',
|
|
30
|
+
MULTINET = 'MULTINET',
|
|
31
|
+
METROPOL = 'METROPOL',
|
|
32
|
+
FASTPAY = 'FASTPAY',
|
|
33
|
+
TICKET = 'TICKET',
|
|
34
|
+
EDENRED = 'EDENRED',
|
|
35
|
+
SETCARD = 'SETCARD',
|
|
36
|
+
SODEXO = 'SODEXO',
|
|
37
|
+
GETIRPAY = 'GETIRPAY',
|
|
38
|
+
TOKENFLEX = 'TOKENFLEX',
|
|
39
|
+
YEMEKMATIK = 'YEMEKMATIK',
|
|
40
|
+
ON_CREDIT = 'ON_CREDIT',
|
|
41
|
+
VIRTUAL_POS = 'VIRTUAL_POS',
|
|
42
|
+
CUZDANPLUS = 'CUZDANPLUS',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum PPPaymentMethod {
|
|
46
|
+
CC = 'CC',
|
|
47
|
+
CASH = 'CASH',
|
|
48
|
+
QR = 'QR',
|
|
49
|
+
QR_R = 'QR_R',
|
|
50
|
+
NFC = 'NFC',
|
|
51
|
+
QUICKCODE = 'QUICKCODE',
|
|
52
|
+
MOBILE = 'MOBILE',
|
|
53
|
+
SWIPE = 'SWIPE',
|
|
54
|
+
NONE = 'NONE',
|
|
55
|
+
ONLINE = 'ONLINE',
|
|
56
|
+
TRENDYOL = 'TRENDYOL',
|
|
57
|
+
GETIR = 'GETIR',
|
|
58
|
+
YEMEKSEPETI = 'YEMEKSEPETI',
|
|
59
|
+
MIGROSYEMEK = 'MIGROSYEMEK',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export enum PPPartialPaymentType {
|
|
63
|
+
AMOUNT = 'AMOUNT',
|
|
64
|
+
PRODUCT = 'PRODUCT',
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export enum PPEodType {
|
|
68
|
+
POS = 'POS',
|
|
69
|
+
CASH = 'CASH',
|
|
70
|
+
BANK_TRANSFER = 'BANK_TRANSFER',
|
|
71
|
+
ONLINE = 'ONLINE',
|
|
72
|
+
OTHER = 'OTHER',
|
|
73
|
+
MULTINET = 'MULTINET',
|
|
74
|
+
SODEXO = 'SODEXO',
|
|
75
|
+
SETCARD = 'SETCARD',
|
|
76
|
+
TICKET = 'TICKET',
|
|
77
|
+
METROPOL = 'METROPOL',
|
|
78
|
+
PAYE = 'PAYE',
|
|
79
|
+
TOKENFLEX = 'TOKENFLEX',
|
|
80
|
+
EDENRED = 'EDENRED',
|
|
81
|
+
CUZDANPLUS = 'CUZDANPLUS',
|
|
82
|
+
IWALLET = 'IWALLET',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export enum PPParameterTypes {
|
|
86
|
+
bank = 'bank',
|
|
87
|
+
multinet = 'multinet',
|
|
88
|
+
metropol = 'metropol',
|
|
89
|
+
paye = 'paye',
|
|
90
|
+
iwallet = 'iwallet',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export enum PPCurrencyType {
|
|
94
|
+
TRY = 'TRY',
|
|
95
|
+
USD = 'USD',
|
|
96
|
+
EUR = 'EUR',
|
|
97
|
+
GBP = 'GBP',
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export enum PPProductTypeEnum {
|
|
101
|
+
PHYSICALLY = 'PHYSICALLY',
|
|
102
|
+
VIRTUAL = 'VIRTUAL',
|
|
103
|
+
INFO = 'INFO',
|
|
104
|
+
MD = 'MD',
|
|
105
|
+
DSN = 'DSN',
|
|
106
|
+
QP = 'QP',
|
|
107
|
+
KFO = 'KFO',
|
|
108
|
+
COMMISSION = 'COMMISSION',
|
|
109
|
+
HGS = 'HGS',
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export enum PPQtyEnums {
|
|
113
|
+
ADET = 'ADET',
|
|
114
|
+
KG = 'KG',
|
|
115
|
+
GR = 'GR',
|
|
116
|
+
LT = 'LT',
|
|
117
|
+
MT = 'MT',
|
|
118
|
+
KOLI = 'KOLI',
|
|
119
|
+
PAKET = 'PAKET',
|
|
120
|
+
PORSIYON = 'PORSIYON',
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export enum PPDiscountTypeEnum {
|
|
124
|
+
PERCENTAGE = 'PERCENTAGE',
|
|
125
|
+
FIXED_AMOUNT = 'FIXED_AMOUNT',
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export enum PPDeliveryTypeEnum {
|
|
129
|
+
CASH_ORDER = 'CASH_ORDER',
|
|
130
|
+
PACKAGE_ORDER = 'PACKAGE_ORDER',
|
|
131
|
+
TABLE_ORDER = 'TABLE_ORDER',
|
|
132
|
+
TAKE_AWAY = 'TAKE_AWAY',
|
|
133
|
+
TAKE_CLOSE = 'TAKE_CLOSE',
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export enum PPDeliveryStatusEnum {
|
|
137
|
+
WAITING = 'WAITING',
|
|
138
|
+
PREPREING = 'PREPREING',
|
|
139
|
+
READY = 'READY',
|
|
140
|
+
ONWAY = 'ONWAY',
|
|
141
|
+
COMPLETE = 'COMPLETE',
|
|
142
|
+
CANCEL = 'CANCEL',
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export enum PPOrderStatusEnum {
|
|
146
|
+
CANCEL = 'CANCEL',
|
|
147
|
+
NOT_RESPONSE = 'NOT_RESPONSE',
|
|
148
|
+
WAITING = 'WAITING',
|
|
149
|
+
SUCCESS = 'SUCCESS',
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export enum PPTransactionStatusEnum {
|
|
153
|
+
SUCCESS = 'SUCCESS',
|
|
154
|
+
CANCEL = 'CANCEL',
|
|
155
|
+
FAIL = 'FAIL',
|
|
156
|
+
NONE = 'NONE',
|
|
157
|
+
WAITING = 'WAITING',
|
|
158
|
+
NOT_RESPONSE = 'NOT_RESPONSE',
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export enum PPDocumentTypeEnum {
|
|
162
|
+
EFATURA = 'EFATURA',
|
|
163
|
+
EARSIV = 'EARSIV',
|
|
164
|
+
BILGIFISI = 'BILGIFISI',
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export enum PPDocumentStatusEnum {
|
|
168
|
+
SUCCESS = 'SUCCESS',
|
|
169
|
+
CANCEL = 'CANCEL',
|
|
170
|
+
FAIL = 'FAIL',
|
|
171
|
+
WAITING = 'WAITING',
|
|
172
|
+
NONE = 'NONE',
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export enum PPOrderSourceEnum {
|
|
176
|
+
POS = 'POS',
|
|
177
|
+
WEB = 'WEB',
|
|
178
|
+
KIOSK = 'KIOSK',
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export enum PPTransactionTypeEnum {
|
|
182
|
+
START = 'START',
|
|
183
|
+
SATIS = 'SATIS',
|
|
184
|
+
CANCEL = 'CANCEL',
|
|
185
|
+
REFUND = 'REFUND',
|
|
186
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when POS+ returns an error (`error_code` / `error_message`) or when
|
|
3
|
+
* the A2A intent cannot be launched.
|
|
4
|
+
*/
|
|
5
|
+
export class PPA2AException extends Error {
|
|
6
|
+
readonly errorCode: string;
|
|
7
|
+
|
|
8
|
+
constructor(errorCode: string, message: string) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'PPA2AException';
|
|
11
|
+
this.errorCode = errorCode;
|
|
12
|
+
// Restore prototype chain (TS target < ES2015 safety).
|
|
13
|
+
Object.setPrototypeOf(this, PPA2AException.prototype);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override toString(): string {
|
|
17
|
+
return `PPA2AException(${this.errorCode}): ${this.message}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PPCurrencyType,
|
|
3
|
+
PPDeliveryStatusEnum,
|
|
4
|
+
PPDeliveryTypeEnum,
|
|
5
|
+
PPDiscountTypeEnum,
|
|
6
|
+
PPEodType,
|
|
7
|
+
PPParameterTypes,
|
|
8
|
+
PPPartialPaymentType,
|
|
9
|
+
PPPaymentMethod,
|
|
10
|
+
PPPaymentType,
|
|
11
|
+
PPProductTypeEnum,
|
|
12
|
+
PPQtyEnums,
|
|
13
|
+
PPTransactionType,
|
|
14
|
+
} from './enums';
|
|
15
|
+
|
|
16
|
+
/** Raw A2A request envelope sent to POS+ (`{ data?, header }`). */
|
|
17
|
+
export interface PPRequest {
|
|
18
|
+
data?: Record<string, any>;
|
|
19
|
+
header: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Formats a Date as `yyyy-MM-dd HH:mm` (the format POS+ expects). */
|
|
23
|
+
export function formatOrderDate(date: Date): string {
|
|
24
|
+
const pad = (n: number) => String(n).padStart(2, '0');
|
|
25
|
+
return (
|
|
26
|
+
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
27
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function header(
|
|
32
|
+
transactionType: PPTransactionType,
|
|
33
|
+
extra?: { orderCode?: string; transactionId?: string }
|
|
34
|
+
): Record<string, any> {
|
|
35
|
+
return {
|
|
36
|
+
transaction_type: transactionType,
|
|
37
|
+
order_code: extra?.orderCode,
|
|
38
|
+
transaction_id: extra?.transactionId,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Billing & product sub-models
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
export interface PPBillingInfo {
|
|
47
|
+
name: string;
|
|
48
|
+
identity: string;
|
|
49
|
+
phone?: string;
|
|
50
|
+
email?: string;
|
|
51
|
+
address?: string;
|
|
52
|
+
city?: string;
|
|
53
|
+
district?: string;
|
|
54
|
+
taxOffice?: string;
|
|
55
|
+
code?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function billingToJson(b?: PPBillingInfo): Record<string, any> | undefined {
|
|
59
|
+
if (!b) return undefined;
|
|
60
|
+
return {
|
|
61
|
+
name: b.name,
|
|
62
|
+
identity: b.identity,
|
|
63
|
+
phone: b.phone,
|
|
64
|
+
email: b.email,
|
|
65
|
+
address: b.address,
|
|
66
|
+
city: b.city,
|
|
67
|
+
district: b.district,
|
|
68
|
+
tax_office: b.taxOffice,
|
|
69
|
+
code: b.code,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Simple product reference used by `startPayment`. */
|
|
74
|
+
export interface PPProduct {
|
|
75
|
+
id: string;
|
|
76
|
+
qty?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Full product line used by `startMultiPayment`. */
|
|
80
|
+
export interface ProductModel {
|
|
81
|
+
id: number;
|
|
82
|
+
sku: string;
|
|
83
|
+
unit: PPQtyEnums;
|
|
84
|
+
price: number;
|
|
85
|
+
title: string;
|
|
86
|
+
quantity: number;
|
|
87
|
+
taxRate: number;
|
|
88
|
+
vatInclude: boolean;
|
|
89
|
+
productType: PPProductTypeEnum;
|
|
90
|
+
discountValue: number;
|
|
91
|
+
description?: string;
|
|
92
|
+
categoryCode?: string;
|
|
93
|
+
categoryName?: string;
|
|
94
|
+
discountType?: PPDiscountTypeEnum;
|
|
95
|
+
exemptionCode?: string;
|
|
96
|
+
/** ÖTV oranı. Default 0. */
|
|
97
|
+
otvOrani?: number;
|
|
98
|
+
/** Konaklama oranı. Default 0. */
|
|
99
|
+
konaklamaOrani?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function productToJson(p: ProductModel): Record<string, any> {
|
|
103
|
+
return {
|
|
104
|
+
id: p.id,
|
|
105
|
+
sku: p.sku,
|
|
106
|
+
unit: p.unit,
|
|
107
|
+
price: p.price,
|
|
108
|
+
title: p.title,
|
|
109
|
+
quantity: p.quantity,
|
|
110
|
+
tax_rate: p.taxRate,
|
|
111
|
+
description: p.description,
|
|
112
|
+
vat_include: p.vatInclude,
|
|
113
|
+
product_type: p.productType,
|
|
114
|
+
discount_value: p.discountValue,
|
|
115
|
+
category_code: p.categoryCode,
|
|
116
|
+
category_name: p.categoryName,
|
|
117
|
+
discount_type: p.discountType,
|
|
118
|
+
exemption_code: p.exemptionCode,
|
|
119
|
+
otv_orani: p.otvOrani ?? 0,
|
|
120
|
+
konaklama_orani: p.konaklamaOrani ?? 0,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface TransactionModel {
|
|
125
|
+
paymentType: PPPaymentType;
|
|
126
|
+
totalAmount: number;
|
|
127
|
+
paymentMethod?: PPPaymentMethod;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function transactionToJson(t: TransactionModel): Record<string, any> {
|
|
131
|
+
return {
|
|
132
|
+
payment_type: t.paymentType,
|
|
133
|
+
total_amount: t.totalAmount,
|
|
134
|
+
payment_method: t.paymentMethod,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// Request builders (`*.toRequest`)
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
export const PPStartPaymentRequestModel = {
|
|
143
|
+
toRequest(params: {
|
|
144
|
+
orderCode: string;
|
|
145
|
+
paymentType: PPPaymentType;
|
|
146
|
+
paymentMethod: PPPaymentMethod;
|
|
147
|
+
totalAmount: number;
|
|
148
|
+
installment?: number;
|
|
149
|
+
isPartial?: boolean;
|
|
150
|
+
partialType?: PPPartialPaymentType;
|
|
151
|
+
products?: PPProduct[];
|
|
152
|
+
billingInformation?: PPBillingInfo;
|
|
153
|
+
}): PPRequest {
|
|
154
|
+
return {
|
|
155
|
+
data: {
|
|
156
|
+
payment_type: params.paymentType,
|
|
157
|
+
payment_method: params.paymentMethod,
|
|
158
|
+
total_amount: params.totalAmount,
|
|
159
|
+
installment: params.installment,
|
|
160
|
+
is_partial: params.isPartial ?? false,
|
|
161
|
+
partial_type: params.partialType,
|
|
162
|
+
products: (params.products ?? []).map((p) => ({
|
|
163
|
+
id: p.id,
|
|
164
|
+
qty: p.qty ?? 1,
|
|
165
|
+
})),
|
|
166
|
+
billing_information: billingToJson(params.billingInformation),
|
|
167
|
+
},
|
|
168
|
+
header: header(PPTransactionType.POST_PAYMENT_START, {
|
|
169
|
+
orderCode: params.orderCode,
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const PPCancelPaymentRequestModel = {
|
|
176
|
+
toRequest(params: {
|
|
177
|
+
orderCode: string;
|
|
178
|
+
transactionId: string;
|
|
179
|
+
note?: string;
|
|
180
|
+
}): PPRequest {
|
|
181
|
+
return {
|
|
182
|
+
data: { transaction_id: params.transactionId, note: params.note },
|
|
183
|
+
header: header(PPTransactionType.POST_PAYMENT_CANCEL, {
|
|
184
|
+
orderCode: params.orderCode,
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const PPEftPaymentRequestModel = {
|
|
191
|
+
toRequest(params: {
|
|
192
|
+
totalAmount: number;
|
|
193
|
+
paymentType: PPPaymentType;
|
|
194
|
+
paymentMethod: PPPaymentMethod;
|
|
195
|
+
transactionId: string;
|
|
196
|
+
taxRate: number;
|
|
197
|
+
installment?: number;
|
|
198
|
+
}): PPRequest {
|
|
199
|
+
return {
|
|
200
|
+
data: {
|
|
201
|
+
total_amount: params.totalAmount,
|
|
202
|
+
payment_type: params.paymentType,
|
|
203
|
+
payment_method: params.paymentMethod,
|
|
204
|
+
transaction_id: params.transactionId,
|
|
205
|
+
tax_rate: params.taxRate,
|
|
206
|
+
installment: params.installment,
|
|
207
|
+
},
|
|
208
|
+
header: header(PPTransactionType.POST_EFTPOS),
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const PPEftCancelRequestModel = {
|
|
214
|
+
toRequest(params: { transactionId: string; totalAmount: number }): PPRequest {
|
|
215
|
+
return {
|
|
216
|
+
data: { total_amount: params.totalAmount },
|
|
217
|
+
header: header(PPTransactionType.POST_EFTPOS_CANCEL, {
|
|
218
|
+
transactionId: params.transactionId,
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const PPOrderPaymentRequestModel = {
|
|
225
|
+
toRequest(params: { orderCode: string }): PPRequest {
|
|
226
|
+
return {
|
|
227
|
+
header: header(PPTransactionType.ORDER_PAYMENT, {
|
|
228
|
+
orderCode: params.orderCode,
|
|
229
|
+
}),
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export const PPEodRequestModel = {
|
|
235
|
+
toRequest(params?: { types?: PPEodType[]; isAll?: boolean }): PPRequest {
|
|
236
|
+
return {
|
|
237
|
+
data: { types: params?.types ?? [], is_all: params?.isAll ?? false },
|
|
238
|
+
header: header(PPTransactionType.EOD),
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export const PPParameterRequestModel = {
|
|
244
|
+
toRequest(params?: {
|
|
245
|
+
types?: PPParameterTypes[];
|
|
246
|
+
isAll?: boolean;
|
|
247
|
+
}): PPRequest {
|
|
248
|
+
return {
|
|
249
|
+
data: { types: params?.types ?? [], is_all: params?.isAll ?? false },
|
|
250
|
+
header: header(PPTransactionType.PARAMETERS),
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export const PPMultiPaymentRequest = {
|
|
256
|
+
toRequest(params: {
|
|
257
|
+
changePaymentStatus: boolean;
|
|
258
|
+
orderCode: string;
|
|
259
|
+
orderDate: Date;
|
|
260
|
+
products: ProductModel[];
|
|
261
|
+
transactions: TransactionModel[];
|
|
262
|
+
billingInformation?: PPBillingInfo;
|
|
263
|
+
groupCode?: string;
|
|
264
|
+
note?: string;
|
|
265
|
+
hash?: string;
|
|
266
|
+
orderNumber?: string;
|
|
267
|
+
userId?: string;
|
|
268
|
+
specialCode?: string;
|
|
269
|
+
startTime?: number;
|
|
270
|
+
discountAmount?: number;
|
|
271
|
+
currency?: PPCurrencyType;
|
|
272
|
+
deliveryStatus?: PPDeliveryStatusEnum;
|
|
273
|
+
deliveryType?: PPDeliveryTypeEnum;
|
|
274
|
+
installment?: number;
|
|
275
|
+
canTryAgain?: boolean;
|
|
276
|
+
}): PPRequest {
|
|
277
|
+
return {
|
|
278
|
+
data: {
|
|
279
|
+
note: params.note,
|
|
280
|
+
user_id: params.userId,
|
|
281
|
+
currency: params.currency ?? PPCurrencyType.TRY,
|
|
282
|
+
customer: billingToJson(params.billingInformation),
|
|
283
|
+
hash: params.hash,
|
|
284
|
+
products: params.products.map(productToJson),
|
|
285
|
+
group_code: params.groupCode,
|
|
286
|
+
order_code: params.orderCode,
|
|
287
|
+
order_date: formatOrderDate(params.orderDate),
|
|
288
|
+
start_time: params.startTime,
|
|
289
|
+
installment: params.installment,
|
|
290
|
+
order_number: params.orderNumber,
|
|
291
|
+
special_code: params.specialCode,
|
|
292
|
+
transactions: params.transactions.map(transactionToJson),
|
|
293
|
+
delivery_type: params.deliveryType ?? PPDeliveryTypeEnum.CASH_ORDER,
|
|
294
|
+
delivery_status: params.deliveryStatus,
|
|
295
|
+
discount_amount: params.discountAmount ?? 0,
|
|
296
|
+
change_payment_status: params.changePaymentStatus,
|
|
297
|
+
can_try_again: params.canTryAgain ?? true,
|
|
298
|
+
},
|
|
299
|
+
header: header(PPTransactionType.ORDER_MULTI_PAYMENT),
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response models. POS+ returns snake_case JSON; these interfaces describe the
|
|
3
|
+
* fields as received (no key remapping) plus an index signature so any extra
|
|
4
|
+
* field POS+ adds stays accessible. Error responses are surfaced as
|
|
5
|
+
* `PPA2AException` by the client before these are returned.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface PPA2AResponse {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface PPStartPaymentResponse extends PPA2AResponse {
|
|
13
|
+
status?: string;
|
|
14
|
+
order_code?: string;
|
|
15
|
+
total_amount?: number;
|
|
16
|
+
total_paid?: number;
|
|
17
|
+
amount_due?: number;
|
|
18
|
+
is_partial?: boolean;
|
|
19
|
+
partial_type?: string;
|
|
20
|
+
card_number_masked?: string;
|
|
21
|
+
rrn?: string;
|
|
22
|
+
payment_type?: string;
|
|
23
|
+
payment_method?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PPOrderPaymentResponse extends PPA2AResponse {
|
|
27
|
+
status?: string;
|
|
28
|
+
completed?: boolean;
|
|
29
|
+
order_code?: string;
|
|
30
|
+
total_amount?: number;
|
|
31
|
+
total_paid?: number;
|
|
32
|
+
amount_due?: number;
|
|
33
|
+
grand_total?: number;
|
|
34
|
+
results?: any[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PPEodResponse extends PPA2AResponse {
|
|
38
|
+
success?: boolean;
|
|
39
|
+
error_message?: string;
|
|
40
|
+
results?: any[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PPParametersResponse extends PPA2AResponse {
|
|
44
|
+
completed?: boolean;
|
|
45
|
+
error_message?: string;
|
|
46
|
+
results?: any[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PPMultiPaymentResponse extends PPA2AResponse {
|
|
50
|
+
order_code?: string;
|
|
51
|
+
status?: string;
|
|
52
|
+
grand_total?: number;
|
|
53
|
+
total_paid?: number;
|
|
54
|
+
products?: any[];
|
|
55
|
+
transactions?: any[];
|
|
56
|
+
}
|