fromJson static method

CommercePaymentMethodResponse? fromJson(
  1. dynamic value
)

Returns a new CommercePaymentMethodResponse instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static CommercePaymentMethodResponse? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key),
            'Required key "CommercePaymentMethodResponse[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "CommercePaymentMethodResponse[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CommercePaymentMethodResponse(
      object:
          CommercePaymentMethodResponseObjectEnum.fromJson(json[r'object'])!,
      id: mapValueOfType<String>(json, r'id')!,
      payerId: mapValueOfType<String>(json, r'payer_id')!,
      paymentType: CommercePaymentMethodResponsePaymentTypeEnum.fromJson(
          json[r'payment_type'])!,
      isDefault: mapValueOfType<bool>(json, r'is_default'),
      gateway: mapValueOfType<String>(json, r'gateway')!,
      gatewayExternalId:
          mapValueOfType<String>(json, r'gateway_external_id')!,
      gatewayExternalAccountId:
          mapValueOfType<String>(json, r'gateway_external_account_id'),
      last4: mapValueOfType<String>(json, r'last4'),
      status:
          CommercePaymentMethodResponseStatusEnum.fromJson(json[r'status'])!,
      walletType: mapValueOfType<String>(json, r'wallet_type'),
      cardType: mapValueOfType<String>(json, r'card_type'),
      expiryYear: mapValueOfType<int>(json, r'expiry_year'),
      expiryMonth: mapValueOfType<int>(json, r'expiry_month'),
      createdAt: mapValueOfType<int>(json, r'created_at'),
      updatedAt: mapValueOfType<int>(json, r'updated_at'),
      isRemovable: mapValueOfType<bool>(json, r'is_removable'),
    );
  }
  return null;
}