onPaymentListener method

  1. @Deprecated("Use PaymongoClient instead")
Future<PaymentResult?> onPaymentListener({
  1. required String paymentMethod,
  2. required PaymentIntentResponse intent,
})

Implementation

@Deprecated("Use PaymongoClient instead")

///
Future<PaymentResult?> onPaymentListener({
  required String paymentMethod,
  required PaymentIntentResponse intent,
}) async {
  try {
    final paymentIntentId =
        intent.attributes.clientKey.split('_client').first;

    final clientKey = intent.attributes.clientKey;
    final attachment = await attachToPaymentIntent(
      paymentIntentId,
      PaymentIntentAttach(
        paymentMethod: paymentMethod,
        clientKey: clientKey,
      ),
    );
    switch (attachment.attributes.status) {
      case "succeeded":
        return PaymentResult(
          id: intent.id,
          clientKey: intent.attributes.clientKey,
          status: PaymentMethodStatus.succeeded,
          paymentMethod: paymentMethod,
          authenticateUrl:
              "https://api.paymongo.com/v1/payment_intents/$paymentIntentId?client_key=$clientKey",
        );
      case "awaiting_payment_method":
        return PaymentResult(
          id: intent.id,
          clientKey: intent.attributes.clientKey,
          status: PaymentMethodStatus.awaitingPaymentMethod,
          errors: intent.attributes.lastPaymentError,
          paymentMethod: paymentMethod,
        );

      case "awaiting_next_action":
        return PaymentResult(
          id: intent.id,
          clientKey: intent.attributes.clientKey,
          status: PaymentMethodStatus.awaitingPaymentMethod,
          errors: intent.attributes.lastPaymentError,
          paymentMethod: paymentMethod,
          authenticateUrl:
              "https://api.paymongo.com/v1/payment_intents/$paymentIntentId?client_key=$clientKey",
          nextAction: attachment.attributes.nextAction,
        );
    }
  } catch (e) {
    rethrow;
  }
  return null;
}