flutter-stripe / flutter_stripe

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

PaymentMethod from Apple Pay #248

Closed romme86 closed 3 years ago

romme86 commented 3 years ago

With Apple Pay is not possible to create a PaymentMethod on the client. While I was able to create a paymentMethod and use it on the server side at a later time with the previous plugin, with this update I am no longer able to do that.

The only thing I am able to get from Apple Pay is a clientSecret.

Is this intended or am I missing something?

jamesblasco commented 3 years ago

In the official native SDK Apple pay is not considered a payment method that can be handled that way.

https://github.com/stripe/stripe-ios/blob/68c36e67ec510ea0dd99510fce375249b0918183/Stripe/STPPaymentMethodEnums.swift

Consider checking the Apple example where we saw how to process payments with Apple Pay.

https://github.com/flutter-stripe/flutter_stripe/blob/main/example/lib/screens/apple_pay_screen.dart

You can create a PaymentIntent in your server and use the clientSecret to confirm it in the client

romme86 commented 3 years ago

Ok, trying to do that results in `flutter: Error: PlatformException(Failed, Payment not completed, null, null)' Do you have a clue on why could this be?

But doing like you said it is not possible to do a payment later in time. For example if my customer asks for a service and has to wait my approval, which could come hours later or the day after, the payment is lost...

romme86 commented 3 years ago

In the official native SDK Apple pay is not considered a payment method that can be handled that way.

https://github.com/stripe/stripe-ios/blob/68c36e67ec510ea0dd99510fce375249b0918183/Stripe/STPPaymentMethodEnums.swift

Consider checking the Apple example where we saw how to process payments with Apple Pay.

https://github.com/flutter-stripe/flutter_stripe/blob/main/example/lib/screens/apple_pay_screen.dart

You can create a PaymentIntent in your server and use the clientSecret to confirm it in the client

I have an update, using xcode i get a more interesting log:


2021-07-30 10:00:47.728540+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_read_handler [C1.1 172.217.168.78:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for read_timeout failed

2021-07-30 10:00:47.728643+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_write_handler [C1.1 172.217.168.78:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for write_timeout failed

2021-07-30 10:00:52.482700+0200 Runner[32674:13297099] LOG ANALYTICS: ["app_name": "MYAPP", "os_version": "14.6", "product_usage": ["STPApplePayContext"], "additional_payment_methods": "none", "analytics_ua": "analytics.stripeios-1.0", "apple_merchant_identifier": "unknown", "app_version": "2.8.8", "apple_pay_enabled": 1, "additional_info": [], "publishable_key": “LIVEKEYXYzy", "shipping_type": "shipping", "bindings_version": "21.5.1", "device_type": "iPhone13,2", "required_billing_address_fields": "zip", "company_name": "MYCOMPANY", "ui_usage_level": "partial", "required_shipping_address_fields": "none", "token_type": "apple_pay", "event": "stripeios.token_creation", "ocr_type": "none"]

2021-07-30 10:00:52.966142+0200 Runner[32674:13297813] [connection] nw_endpoint_handler_set_adaptive_read_handler [C3.1 34.240.123.193:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for read_timeout failed

2021-07-30 10:00:52.966365+0200 Runner[32674:13297813] [connection] nw_endpoint_handler_set_adaptive_write_handler [C3.1 34.240.123.193:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for write_timeout failed

2021-07-30 10:00:53.462302+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_read_handler [C2.1 54.187.119.242:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for read_timeout failed

2021-07-30 10:00:53.462624+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_write_handler [C2.1 54.187.119.242:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for write_timeout failed

2021-07-30 10:00:53.467004+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_read_handler [C4.1 44.242.31.105:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for read_timeout failed

2021-07-30 10:00:53.467197+0200 Runner[32674:13297758] [connection] nw_endpoint_handler_set_adaptive_write_handler [C4.1 44.242.31.105:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, dns, expensive)] unregister notification for write_timeout failed

2021-07-30 10:00:53.645213+0200 Runner[32674:13297099] LOG ANALYTICS: ["device_type": "iPhone13,2", "os_version": "14.6", "app_name": “MYAPP”, "shipping_type": "shipping", "apple_merchant_identifier": "unknown", "bindings_version": "21.5.1", "app_version": "2.8.8", "publishable_key": “LIVEKEYXYzy", "apple_pay_enabled": 1, "ocr_type": "none", "required_shipping_address_fields": "none", "analytics_ua": "analytics.stripeios-1.0", "event": "stripeios.payment_method_creation", "additional_info": [], "required_billing_address_fields": "zip", "source_type": "card", "additional_payment_methods": "none", "product_usage": ["STPApplePayContext"], "ui_usage_level": "partial", "company_name": “MYCOMPANY]

2021-07-30 10:00:58.076083+0200 Runner[32674:13297334] [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: PlatformException(Failed, Payment not completed, null, null)

#0      JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:155:7)

#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)

<asynchronous suspension>

#2      MethodChannelStripe.confirmApplePayPayment (package:stripe_platform_interface/src/method_channel_stripe.dart:70:5)

<asynchronous suspension>

#3      Stripe.confirmApplePayPayment (package:flutter_stripe/src/stripe.dart:201:7)

<asynchronous suspension>

#4      ConfirmOrderState._handlePayPress (package:Buytime/UI/user/cart/UI_U_ConfirmOrder.dart:1096:34)

<asynchronous suspension>

i think that this may be an issue, "apple_merchant_identifier": "unknown"

but i set up the merchant identifier as in the examples and also in xcode as per Stripe official integration guide. (apple pay was working with the old plugin)

the stack issue is generated here I guess: image

romme86 commented 3 years ago

@jamesblasco @jonasbark I solved the issue. Thanks to the stripe support we realised that using the Connect platform the connected_customer_id has to be associated to the flutter_stripe configuration when confirming payments on the device.

so the trick is to set: Stripe.stripeAccountId = {CONNECTED_ACCOUNT_ID}

is there the possibility to add this and similar cases to the library documentation? I believe we are going to need this knowledge for similar use cases in the future...

jonasbark commented 3 years ago

Thanks for sharing what fixed it for you