flutter-stripe / flutter_stripe

Flutter SDK for Stripe.
https://pub.dev/packages/flutter_stripe
960 stars 528 forks source link

can't decode onApplePayResult dynamic value #992

Closed heshesh2010 closed 2 years ago

heshesh2010 commented 2 years ago

Hi , my apple pay button works great and return the token but i just need these values from onApplePayResult :

transactionId,
ephemeralPublicKey,
publicKeyHash,
data,
signature,
version,
transactionIdentifier,
network,
displayName,
type,

i'm using this code

void onApplePayResult(paymentResult) {

if (paymentResult is String) {
  Fluttertoast.showToast(
      msg: "String",
      toastLength: Toast.LENGTH_LONG,
      gravity: ToastGravity.TOP);
}

if (paymentResult is Map) {
  Fluttertoast.showToast(
      msg: "map",
      toastLength: Toast.LENGTH_LONG,
      gravity: ToastGravity.TOP);
}

Map result = jsonDecode(paymentResult); // give me error 

//  String transactionIdentifier = jsonDecode(paymentResult["transactionIdentifier"]);

String network = result['token']['network'];
String displayName = result['token']['displayName'];
String type = result['token']['type'].toString();

String version = result['token']['version'].toString();
String data = result['token']['data'];
String signature = result['token']['signature'];
String ephemeralPublicKey = result['header']['ephemeralPublicKey'];
String publicKeyHash = result['header']['publicKeyHash'];
String transactionId = result['header']['transactionId'].toString();

}

remonh87 commented 2 years ago

Can you explain more why you need this information? You normally get this data when the backend creates a payment intent.

The token is encrypted so you cannot decode it using json decode. For more info see: https://developer.apple.com/documentation/passkit/apple_pay/payment_token_format_reference