fromJson static method

CommercePaymentSourceResponse? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static CommercePaymentSourceResponse? 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 "CommercePaymentSourceResponse[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "CommercePaymentSourceResponse[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CommercePaymentSourceResponse(
      object:
          CommercePaymentSourceResponseObjectEnum.fromJson(json[r'object'])!,
      id: mapValueOfType<String>(json, r'id')!,
      payerId: mapValueOfType<String>(json, r'payer_id')!,
      paymentMethod: CommercePaymentSourceResponsePaymentMethodEnum.fromJson(
          json[r'payment_method'])!,
      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:
          CommercePaymentSourceResponseStatusEnum.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;
}