PaymentIntent.fromJson constructor

PaymentIntent.fromJson(
  1. Object? json
)

Implementation

factory PaymentIntent.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return PaymentIntent(
    amount: (map['amount'] as num).toInt(),
    amountCapturable: (map['amount_capturable'] as num).toInt(),
    amountDetails: map['amount_details'] == null
        ? null
        : PaymentFlowsAmountDetails.fromJson(map['amount_details']),
    amountReceived: (map['amount_received'] as num).toInt(),
    application: map['application'] == null
        ? null
        : ApplicationOrId.fromJson(map['application']),
    applicationFeeAmount: map['application_fee_amount'] == null
        ? null
        : (map['application_fee_amount'] as num).toInt(),
    automaticPaymentMethods: map['automatic_payment_methods'] == null
        ? null
        : PaymentFlowsAutomaticPaymentMethodsPaymentIntent.fromJson(
            map['automatic_payment_methods']),
    canceledAt: map['canceled_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['canceled_at'] as int).toInt()),
    cancellationReason: map['cancellation_reason'] == null
        ? null
        : PaymentIntentCancellationReason.fromJson(
            map['cancellation_reason']),
    captureMethod: PaymentIntentCaptureMethod.fromJson(map['capture_method']),
    clientSecret: map['client_secret'] == null
        ? null
        : (map['client_secret'] as String),
    confirmationMethod:
        CustomerBalanceCustomerBalanceSettingsReconciliationMode.fromJson(
            map['confirmation_method']),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    currency: (map['currency'] as String),
    customer: map['customer'] == null
        ? null
        : BankAccountCustomerOrId.fromJson(map['customer']),
    description:
        map['description'] == null ? null : (map['description'] as String),
    id: (map['id'] as String),
    invoice:
        map['invoice'] == null ? null : InvoiceOrId.fromJson(map['invoice']),
    lastPaymentError: map['last_payment_error'] == null
        ? null
        : ApiErrors.fromJson(map['last_payment_error']),
    latestCharge: map['latest_charge'] == null
        ? null
        : ChargeOrId.fromJson(map['latest_charge']),
    livemode: (map['livemode'] as bool),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    nextAction: map['next_action'] == null
        ? null
        : PaymentIntentNextAction.fromJson(map['next_action']),
    onBehalfOf: map['on_behalf_of'] == null
        ? null
        : AccountOrId.fromJson(map['on_behalf_of']),
    paymentMethod: map['payment_method'] == null
        ? null
        : PaymentMethodOrId.fromJson(map['payment_method']),
    paymentMethodConfigurationDetails:
        map['payment_method_configuration_details'] == null
            ? null
            : CheckoutSessionPaymentMethodConfigurationDetails.fromJson(
                map['payment_method_configuration_details']),
    paymentMethodOptions: map['payment_method_options'] == null
        ? null
        : PaymentIntentPaymentMethodOptions.fromJson(
            map['payment_method_options']),
    paymentMethodTypes: (map['payment_method_types'] as List<Object?>)
        .map((el) => (el as String))
        .toList(),
    processing: map['processing'] == null
        ? null
        : PaymentIntentProcessing.fromJson(map['processing']),
    receiptEmail: map['receipt_email'] == null
        ? null
        : (map['receipt_email'] as String),
    review: map['review'] == null ? null : ReviewOrId.fromJson(map['review']),
    setupFutureUsage: map['setup_future_usage'] == null
        ? null
        : ConfirmationTokenSetupFutureUsage.fromJson(
            map['setup_future_usage']),
    shipping: map['shipping'] == null
        ? null
        : ChargeShipping.fromJson(map['shipping']),
    source: map['source'] == null
        ? null
        : PaymentIntentSourceOrId.fromJson(map['source']),
    statementDescriptor: map['statement_descriptor'] == null
        ? null
        : (map['statement_descriptor'] as String),
    statementDescriptorSuffix: map['statement_descriptor_suffix'] == null
        ? null
        : (map['statement_descriptor_suffix'] as String),
    status: PaymentIntentStatus.fromJson(map['status']),
    transferData: map['transfer_data'] == null
        ? null
        : PaymentIntentTransferData.fromJson(map['transfer_data']),
    transferGroup: map['transfer_group'] == null
        ? null
        : (map['transfer_group'] as String),
  );
}