forked from ignertic/paynow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_express_checkout_status_stream.dart
54 lines (41 loc) · 1.74 KB
/
test_express_checkout_status_stream.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
import '../lib/paynow.dart';
// test payment status stream
void main() async {
// USE YOUR KEYS WHEN TESTING A PAYMENT.
// THESE KEYS WERE ONLY USED FOR TESTING AND HAVE BEEN REVOKED
const String PAYNOW_INTEGRATION_ID = "6054";
const String PAYNOW_INTEGRATION_KEY = "960ad10a-fc0c-403b-af14-e9520a50fbf4";
const String PAYNOW_EMAIL = '[email protected]';
const String RESULT_URL = 'http:/google.com/q=yoursite';
const String RETURN_URL = 'http://google.com/q=yoursite';
final paynow = Paynow(
integrationId: PAYNOW_INTEGRATION_ID,
integrationKey: PAYNOW_INTEGRATION_KEY,
returnUrl: RETURN_URL,
resultUrl: RESULT_URL
);
final Payment payment = paynow.createPayment('reference-test', PAYNOW_EMAIL);
final cartItem1 = PaynowCartItem(title: 'test-item', amount: 20.0);
// add item to cart
payment.addToCart(cartItem1);
// perform Express Checkout
// final InitResponse paynowResponse = await paynow.sendMobile(payment, '0784442662', method: "ecocash");
final InitResponse paynowResponse = await paynow.send(payment);
// display response data
print(paynowResponse.toString());
print('=== once off check status ====');
final StatusResponse paynowStatusResponse = await paynow.checkTransactionStatus(paynowResponse.pollUrl);
print(paynowStatusResponse.toString());
print('==== listening to status stream =====');
var _stream = paynow.streamTransactionStatus(paynowResponse.pollUrl, streamInterval: 5);
// listen to status changes as opposed to delay and polling
_stream.listen(
(event) {
print('=== stream event at: ${DateTime.now()} | event: $event');
if (event.status != 'Sent') {
paynow.closeStream();
}
},
);
print('Mobile Express Chekout Testing Complete');
}