Native Pay Methods

Apple Pay

In the Flutter SDK, Apple Pay can be used to process payments with a smooth, native experience. Before displaying the Apple Pay sheet, it is essential to:

  1. (Optionally) configure Apple Pay to collect billing data
  2. Ensure the device supports Apple Pay
  3. Generate a payment receipt and then submit it once the intentId is available.

1. (Optional) Configuring Apple Pay to Collect Billing Data

If you need to collect specific billing data—such as an email address—during the Apple Pay process, configure the SDK using ApplePayConfiguration:

import 'package:moneyhash/moneyhash.dart';

void main() {
  final applePayConfig = ApplePayConfiguration(
    collectibleBillingData: [CollectibleBillingData.email],
  );

  final moneyHash = MoneyHashSDKBuilder()
      .setNativeApplePayConfig(applePayConfig)
      .build();
}
  • Supported values: CollectibleBillingData.email
  • To disable billing data collection, use an empty list [].

2. Check if the Device is Compatible with Apple Pay

Call isDeviceCompatibleWithApplePay() to determine if Apple Pay is supported on the current device:

final isCompatible = await moneyHash.isDeviceCompatibleWithApplePay();

if (isCompatible) {
  // Proceed with Apple Pay
} else {
  print("This device does not support Apple Pay");
}

This method is only valid on iOS. Calling it on unsupported platforms will throw an UnsupportedError.


Apple Pay Flow: Two-Step Approach

The new flow separates receipt generation from payment submission. This allows you to:

  • Collect Apple Pay payment authorization first (no intent needed)
  • Finalize the payment later when you have the intentId

Step 1: Generate the Apple Pay Receipt

Use generateApplePayReceipt() with the new ApplePayReceiptParams object. You can either pass raw data or use an existing ApplePayData object from the intent state.

Option A: Using NativePay + ApplePayData

if (intentState is NativePay) {
  final applePayData = intentState.nativePayData as ApplePayData?;

  if (applePayData != null) {
    final receipt = await moneyHash.generateApplePayReceipt(
      ApplePayReceiptParams.withApplePayData(
        applePayData.amount ?? 0.0,
        applePayData,
      ),
    );

    if (receipt != null) {
      print("Apple Pay Receipt generated successfully: $receipt");
      // Submit later with intentId
    }
  }
}

Option B: Manually Providing Custom Apple Pay Fields

final receipt = await moneyHash.generateApplePayReceipt(
  ApplePayReceiptParams.withCustomData(
    depositAmount: 10.0,
    merchantIdentifier: 'merchant.com.example',
    currencyCode: 'USD',
    countryCode: 'US',
    supportedNetworks: ['visa', 'masterCard'],
    merchantCapabilities: ['supports3DS'],
  ),
);

if (receipt != null) {
  print("Apple Pay Receipt generated: $receipt");
}

Step 2: Submit the Payment Receipt

Once you’ve created or obtained the intentId, submit the NativePayReceipt:

final intentId = "<intent_id>"; // From your backend

final intentDetails = await moneyHash.submitPaymentReceipt(
  intentId,
  receipt,
);

if (intentDetails != null) {
  print("Payment completed successfully: $intentDetails");
}

⚠️

The receipt is only valid for a limited time. Be sure to submit it shortly after generation.


Google Pay

(No changes from your original text are required here, since the question specifically requested Apple Pay documentation updates. The Google Pay documentation remains as provided.)


Summary

  1. Configure (Optional): Call setNativeApplePayConfig(...) in MoneyHashSDKBuilder to specify any billing data Apple Pay may collect (e.g., email).
  2. Check Compatibility: Always verify that the device supports Apple Pay using isDeviceCompatibleWithApplePay().
  3. Approach #1 (Direct): If you already have an intentId, use proceedWithApplePay to handle everything in one go.
  4. Approach #2 (Two-Step): If you don’t have an intentId initially or want to separate generation of the Apple Pay receipt from final payment submission, use generateApplePayReceipt first, then call submitPaymentReceipt once you have the intentId.

By following these steps, you can integrate Apple Pay into your Flutter application using the MoneyHash SDK, providing users with a seamless and secure payment experience.