google-pay / google-pay/flutter-plugin
Apple Pay Bottom Sheet – Incorrect Failure Design Handling After Backend Call Using Apple Pay Token
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 176
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
Dear All
Kindly Inform You
We are facing an issue with Apple Pay payment flow when handling async order creation.
Current flow:
- User opens Apple Pay bottom sheet.
- Payment token is generated automatically by Apple Pay.
- User confirms payment via Face ID / double click.
- We call our backend
createOrderAPI after authorization. - We need to wait for the API response before dismissing the Apple Pay sheet.
to handle Bottom Sheet Message "Done" or "Payment Failed" the Current situation now it return All the time as "Done" but we need if the backend replay to us as Payment Failed show this "Payment Failed" to the user
Expected behavior:
- If the API succeeds → show payment success.
- If the API fails → keep the sheet open and show “Payment Failed”.
Issue:
Apple Pay requires PKPaymentAuthorizationResult to be returned immediately, but our order creation is async. There is no clear way to keep the Apple Pay bottom sheet active until the backend response is received, and then emit success or failure properly.
Currently, even when the backend fails, the sheet dismisses before we can show an error.
Question:
What is the recommended way to:
- Delay completion of
didAuthorizePayment - Wait for backend response
- Return
.successor.failuredynamically - Display “Payment Failed” without dismissing the Apple Pay sheet prematurely?
Please find below the payment configuration I'm using:
ApplePayButton(
paymentConfiguration: PaymentConfiguration.fromJsonString(
'''{
"provider": "apple_pay",
"data": {
"merchantIdentifier": "$merchantId",
"displayName": "App Name",
"merchantCapabilities": ["3DS", "debit", "credit"],
"supportedNetworks": ["amex", "visa", "discover", "masterCard","Visa","mada"],
"countryCode": "SA",
"currencyCode": "SAR",
"requiredBillingContactFields": [],
"requiredShippingContactFields": [],
"shippingMethods": []
}
}''',
),
paymentItems: [
PaymentItem(
label: 'App Name',
amount: amount,
status: PaymentItemStatus.final_price,
),
],
style: ApplePayButtonStyle.black,
type: ApplePayButtonType.inStore,
width: double.infinity,
height: 50,
onPaymentResult: onPressed,
onPressed: onClick,
loadingIndicator: Center(child: CircularProgressIndicator()),
)
and this is the code that we use it in native IOS swift App
func paymentAuthorizationController(
_ controller: PKPaymentAuthorizationController,
didAuthorizePayment payment: PKPayment,
handler completion: @escaping (PKPaymentAuthorizationResult) -> Void
) {
createOrder(paymentToken: payment.token) { result in
switch result {
case .success:
completion(
PKPaymentAuthorizationResult(status: .success)
)
case .failure:
completion(
PKPaymentAuthorizationResult(
status: .failure,
errors: [NSError(
domain: PKPaymentErrorDomain,
code: PKPaymentError.Code.unknownError.rawValue,
userInfo: [NSLocalizedDescriptionKey: "Payment Failed"]
)]
)
)
}
}
}
Beast Regards
Mohamed Elgammal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Flutter ApplePayButton configuration and the native iOS paymentAuthorizationController callback shown in the issue. Reproduce an asynchronous createOrder failure and inspect how the plugin handles the completion handler and payment result. Done means the supported behavior for delayed success or failure is identified and documented or exposed consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter, ios, swift
- Domain
- mobile, payments
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100