Created
July 2, 2020 13:55
-
-
Save wesleyguirra/48e2f48c1177c248b6ad6825d49b5772 to your computer and use it in GitHub Desktop.
Classe com a implementação dos métodos dart para o flutter_paystore_client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:collection'; | |
import 'package:flutter/services.dart'; | |
import 'package:flutter_paystore_client/flutter_paystore_client.dart'; | |
import 'package:flutter_paystore_client/src/reverse_payment_request.dart'; | |
class FlutterPaystoreClient { | |
static const MethodChannel _channel = const MethodChannel('flutter_paystore_client'); | |
static Future<void> bindClient() async { | |
try { | |
await _channel.invokeMethod('bindClient'); | |
} catch (error) { | |
throw error; | |
} | |
} | |
static Future<String> startPaymentV2(PaymentRequest paymentRequest) async { | |
try { | |
final String payment = await _channel.invokeMethod('startPaymentV2', <String, dynamic>{ | |
'transactionId': paymentRequest.appTransactionId, | |
'value': paymentRequest.value, | |
'appVersion': paymentRequest.applicationInfo.softwareVersion, | |
'token': paymentRequest.applicationInfo.credentials.token, | |
'tokenizeEmail': paymentRequest.tokenizeEmail, | |
'applicationId': paymentRequest.applicationInfo.credentials.applicationId, | |
}); | |
return Future.value(payment); | |
} catch (error) { | |
return Future.value(error); | |
} | |
} | |
static Future<Map<String, dynamic>> startPayment(PaymentRequest paymentRequest) async { | |
try { | |
final LinkedHashMap<dynamic, dynamic> paymentHashMap = await _channel.invokeMethod('startPayment', <String, dynamic>{ | |
'transactionId': paymentRequest.appTransactionId, | |
'value': paymentRequest.value, | |
'appVersion': paymentRequest.applicationInfo.softwareVersion, | |
'token': paymentRequest.applicationInfo.credentials.token, | |
'applicationId': paymentRequest.applicationInfo.credentials.applicationId, | |
'paymentTypes': PaymentRequest.mapPaymentTypesToName(paymentRequest.paymentTypes) | |
}); | |
Map<String, dynamic> payment = Map.from(paymentHashMap); | |
return Future.value(payment); | |
} catch (error) { | |
return Future.error(error); | |
} | |
} | |
static Future<Map<String, dynamic>> confirmPayment(String paymentId, Credentials credentials) async { | |
try { | |
final Map<String, dynamic> payment = await _channel.invokeMethod('confirmPayment', <String, dynamic>{ | |
'paymentId': paymentId, | |
'token': credentials.token, | |
'applicationId': credentials.applicationId, | |
}); | |
return Future.value(payment); | |
} catch (error) { | |
return Future.value(error); | |
} | |
} | |
static Future<Map<String, dynamic>> reversePayment(ReversePaymentRequest reversePaymentRequest) async { | |
try { | |
final Map<String, dynamic> reversePayment = await _channel.invokeMethod('reversePayment', <String, dynamic>{ | |
'value': reversePaymentRequest.value, | |
'paymentId': reversePaymentRequest.paymentId, | |
'transactionId': reversePaymentRequest.appTransactionId, | |
'token': reversePaymentRequest.applicationInfo.credentials.token, | |
'applicationId': reversePaymentRequest.applicationInfo.credentials.applicationId, | |
'appVersion': reversePaymentRequest.applicationInfo.softwareVersion, | |
'showReceiptView': reversePaymentRequest.showReceiptView | |
}); | |
return Future.value(reversePayment); | |
} catch (error) { | |
return Future.error(error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment