-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.dart
208 lines (200 loc) · 6.56 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import 'package:flutter/material.dart';
import 'package:mad_pay/mad_pay.dart';
void main() {
runApp(MyApp());
}
/// Test app
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final MadPay pay = MadPay();
final List<PaymentItem> items = <PaymentItem>[
PaymentItem(name: 'T-Shirt', price: 2.98),
PaymentItem(name: 'Trousers', price: 15.24),
];
final AppleParameters appleParameters = AppleParameters(
merchantIdentifier: 'example_id',
billingContact: Contact(
emailAddress: 'test@test.com',
postalAddress: PostalAddress(
street: 's',
city: 'c',
state: 'st',
postalCode: '123321',
country: 'ct',
),
name: PersonNameComponents(
familyName: 'qwe',
middleName: 'ewq',
namePrefix: 'a',
nameSuffix: 'h',
nickname: 'test',
phoneticRepresentation: PersonNameComponents(
middleName: 'ewq2',
givenName: 'rty2',
namePrefix: 'a2',
nameSuffix: 'h2',
nickname: 'test2',
),
),
),
shippingContact: Contact(
emailAddress: 'test@test.com',
),
merchantCapabilities: <MerchantCapabilities>[
MerchantCapabilities.threeds,
MerchantCapabilities.credit,
],
);
final GoogleParameters googleParameters = GoogleParameters(
gatewayName: 'example',
gatewayMerchantId: 'example_id',
merchantId: 'TEST',
merchantName: 'Test',
cardParameters: CardParameters(
billingAddressRequired: true,
billingAddressParameters: BillingAddressParameters(
billingFormat: BillingFormat.full,
phoneNumberRequired: true,
),
),
transactionInfo: TransactionInfo(
totalPriceLabel: 'Test',
checkoutOption: CheckoutOption.completeImmediatePurchase,
),
shippingAddressRequired: true,
shippingAddressParameters: ShippingAddressParameters(
phoneNumberRequired: true,
),
);
String result = 'Result will be shown here';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(result),
TextButton(
onPressed: () async {
try {
final bool req = await pay.checkPayments();
setState(() {
result = 'Can make payments: $req';
});
} catch (e) {
setState(() {
result = 'Error:\n$e';
});
}
},
child: const Text('Can make payments?'),
),
TextButton(
onPressed: () async {
try {
final bool req = await pay.checkActiveCard(
paymentNetworks: <PaymentNetwork>[
PaymentNetwork.visa,
PaymentNetwork.mastercard,
],
);
setState(() {
result = 'Can make payments with verified card: $req';
});
} catch (e) {
setState(() {
result = 'Error:\n$e';
});
}
},
child: const Text('Can make payments with verified card?'),
),
TextButton(
onPressed: () async {
try {
final PaymentResponse? req = await pay.processingPayment(
PaymentRequest(
google: googleParameters,
apple: appleParameters,
currencyCode: 'USD',
countryCode: 'US',
paymentItems: items,
paymentNetworks: <PaymentNetwork>[
PaymentNetwork.visa,
PaymentNetwork.mastercard,
],
),
);
setState(() {
result = 'Try to pay:\n${req?.token}';
});
} catch (e) {
setState(() {
result = 'Error:\n$e';
});
}
},
child: const Text('Try to pay?'),
),
AdaptivePayButton(
applePayButton: ApplePayButton(
style: ApplePayButtonStyle.automatic,
type: ApplePayButtonType.buy,
request: PaymentRequest.apple(
apple: appleParameters,
currencyCode: 'USD',
countryCode: 'US',
paymentItems: items,
),
onPaymentResult: (PaymentResponse? req) {
setState(() {
result = 'ApplePayButton, Try to pay:\n${req?.token}';
});
},
onError: (Object? e) {
setState(() {
result = 'ApplePayButton, Error:\n$e';
});
},
),
googlePayButton: GooglePayButton(
type: GooglePayButtonType.plain,
request: PaymentRequest.google(
paymentNetworks: <PaymentNetwork>[
PaymentNetwork.amex,
PaymentNetwork.discover,
PaymentNetwork.interac,
PaymentNetwork.jcb,
PaymentNetwork.mastercard,
PaymentNetwork.visa,
PaymentNetwork.mir,
],
google: googleParameters,
currencyCode: 'USD',
countryCode: 'US',
paymentItems: items,
),
onPaymentResult: (PaymentResponse? req) {
setState(() {
result = 'GooglePayButton, Try to pay:\n${req?.token}';
});
},
onError: (Object? e) {
setState(() {
result = 'GooglePayButton, Error:\n$e';
});
},
),
),
],
),
),
),
);
}
}