Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional fields #51

Merged
merged 13 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string>com.adyen.adyen_checkout_example</string>
<key>CFBundleURLSchemes</key>
<array>
<string>ui-host</string>
<string>flutter-ui-host</string>
</array>
</dict>
</array>
Expand Down
2 changes: 1 addition & 1 deletion example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Config {
static const Environment environment = Environment.test;
static const String baseUrl = "checkout-test.adyen.com";
static const String apiVersion = "v70";
static const String iOSReturnUrl = "ui-host://payments";
static const String iOSReturnUrl = "flutter-ui-host://payments";

//Example data
static Amount amount = Amount(currency: "EUR", value: 2100);
Expand Down
11 changes: 9 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class _MyAppState extends State<MyApp> {
final CashAppPayConfiguration cashAppPayConfiguration =
await _createCashAppPayConfiguration();

final ApplePayConfiguration applePayConfiguration = ApplePayConfiguration(
merchantId: Config.merchantAccount,
merchantName: Config.merchantName,
);

final DropInConfiguration dropInConfiguration = DropInConfiguration(
environment: Environment.test,
clientKey: Config.clientKey,
Expand All @@ -115,6 +120,7 @@ class _MyAppState extends State<MyApp> {
cardsConfiguration: cardsConfiguration,
storedPaymentMethodConfiguration: storedPaymentMethodConfiguration,
cashAppPayConfiguration: cashAppPayConfiguration,
applePayConfiguration: applePayConfiguration,
);

return await _adyenCheckout.startPayment(
Expand All @@ -129,8 +135,9 @@ class _MyAppState extends State<MyApp> {
final String paymentMethodsResponse =
await _adyenSessionRepository.fetchPaymentMethods();

final CardsConfiguration cardsConfiguration =
CardsConfiguration(showStorePaymentField: true);
final CardsConfiguration cardsConfiguration = CardsConfiguration(
showStorePaymentField: true,
);

final ApplePayConfiguration applePayConfiguration = ApplePayConfiguration(
merchantId: Config.merchantAccount,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/network/models/amount_network_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AmountNetworkModel {
final String? currency;
final String currency;
final int value;

AmountNetworkModel({
Expand Down
33 changes: 33 additions & 0 deletions example/lib/network/models/billing_address.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class BillingAddress {
String? city;
String? country;
String? houseNumberOrName;
String? postalCode;
String? street;

BillingAddress({
this.city,
this.country,
this.houseNumberOrName,
this.postalCode,
this.street,
});

BillingAddress.fromJson(Map<String, dynamic> json) {
city = json['city'];
country = json['country'];
houseNumberOrName = json['houseNumberOrName'];
postalCode = json['postalCode'];
street = json['street'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['city'] = city;
data['country'] = country;
data['houseNumberOrName'] = houseNumberOrName;
data['postalCode'] = postalCode;
data['street'] = street;
return data;
}
}
45 changes: 45 additions & 0 deletions example/lib/network/models/delivery_address.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class DeliveryAddress {
Robert-SD marked this conversation as resolved.
Show resolved Hide resolved
String? city;
String? country;
String? houseNumberOrName;
String? postalCode;
String? street;
String? firstName;
String? lastName;
String? stateOrProvince;

DeliveryAddress({
this.city,
this.country,
this.houseNumberOrName,
this.postalCode,
this.street,
this.firstName,
this.lastName,
this.stateOrProvince
});

DeliveryAddress.fromJson(Map<String, dynamic> json) {
city = json['city'];
country = json['country'];
houseNumberOrName = json['houseNumberOrName'];
postalCode = json['postalCode'];
street = json['street'];
firstName = json['firstname'];
lastName = json['firstname'];
stateOrProvince = json['stateOrProvince'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['city'] = city;
data['country'] = country;
data['houseNumberOrName'] = houseNumberOrName;
data['postalCode'] = postalCode;
data['street'] = street;
data['firstName'] = firstName;
data['lastName'] = lastName;
data['stateOrProvince'] = stateOrProvince;
return data;
}
}
49 changes: 49 additions & 0 deletions example/lib/network/models/line_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class LineItem {
int? quantity;
int? amountExcludingTax;
int? taxPercentage;
String? description;
String? id;
int? taxAmount;
int? amountIncludingTax;
String? productUrl;
String? imageUrl;

LineItem({
this.quantity,
this.amountExcludingTax,
this.taxPercentage,
this.description,
this.id,
this.taxAmount,
this.amountIncludingTax,
this.productUrl,
this.imageUrl,
});

LineItem.fromJson(Map<String, dynamic> json) {
quantity = json['quantity'];
amountExcludingTax = json['amountExcludingTax'];
taxPercentage = json['taxPercentage'];
description = json['description'];
id = json['id'];
taxAmount = json['taxAmount'];
amountIncludingTax = json['amountIncludingTax'];
productUrl = json['productUrl'];
imageUrl = json['imageUrl'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['quantity'] = quantity;
data['amountExcludingTax'] = amountExcludingTax;
data['taxPercentage'] = taxPercentage;
data['description'] = description;
data['id'] = id;
data['taxAmount'] = taxAmount;
data['amountIncludingTax'] = amountIncludingTax;
data['productUrl'] = productUrl;
data['imageUrl'] = imageUrl;
return data;
}
}
40 changes: 6 additions & 34 deletions example/lib/network/models/payment_request_network_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:adyen_checkout_example/network/models/amount_network_model.dart';
import 'package:adyen_checkout_example/network/models/line_item.dart';
import 'package:adyen_checkout_example/network/models/session_request_network_model.dart';

class PaymentsRequestData {
Expand All @@ -12,10 +13,11 @@ class PaymentsRequestData {
final bool? threeDSAuthenticationOnly;
final String? shopperIP;
final String? channel;
final List<Item>? lineItems;
final List<LineItem>? lineItems;
final String? shopperEmail;
final ThreeDS2RequestDataRequest? threeDS2RequestData;
final RecurringProcessingModel? recurringProcessingModel;
final String? shopperInteraction;

PaymentsRequestData({
required this.merchantAccount,
Expand All @@ -32,6 +34,7 @@ class PaymentsRequestData {
this.shopperEmail,
this.threeDS2RequestData,
this.recurringProcessingModel,
this.shopperInteraction,
});

Map<String, dynamic> toJson() {
Expand All @@ -48,12 +51,13 @@ class PaymentsRequestData {
"reference": reference,
if (channel != null) "channel": channel,
if (lineItems != null)
"lineItems": lineItems?.map((item) => item.toJson()).toList(),
"lineItems": lineItems?.map((lineItem) => lineItem.toJson()).toList(),
if (shopperEmail != null) "shopperEmail": shopperEmail,
if (threeDS2RequestData != null)
"threeDS2RequestData": threeDS2RequestData?.toJson(),
if (recurringProcessingModel != null)
"recurringProcessingModel": recurringProcessingModel?.recurringModelString,
if (shopperInteraction != null) "shopperInteraction" : shopperInteraction
};
}
}
Expand All @@ -75,38 +79,6 @@ class AdditionalData {
}
}

class Item {
final int quantity;
final int amountExcludingTax;
final int taxPercentage;
final String description;
final String id;
final int amountIncludingTax;
final String taxCategory;

Item({
required this.quantity,
required this.amountExcludingTax,
required this.taxPercentage,
required this.description,
required this.id,
required this.amountIncludingTax,
required this.taxCategory,
});

Map<String, dynamic> toJson() {
return {
'quantity': quantity,
'amountExcludingTax': amountExcludingTax,
'taxPercentage': taxPercentage,
'description': description,
'id': id,
'amountIncludingTax': amountIncludingTax,
'taxCategory': taxCategory,
};
}
}

class ThreeDS2RequestDataRequest {
final String deviceChannel;
final String challengeIndicator;
Expand Down
50 changes: 50 additions & 0 deletions example/lib/network/models/session_request_network_model.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
import 'dart:convert';

import 'package:adyen_checkout_example/network/models/amount_network_model.dart';
import 'package:adyen_checkout_example/network/models/billing_address.dart';
import 'package:adyen_checkout_example/network/models/delivery_address.dart';
import 'package:adyen_checkout_example/network/models/line_item.dart';

class SessionRequestNetworkModel {
final String merchantAccount;
final AmountNetworkModel amount;
final String returnUrl;
final String reference;
final String countryCode;
final String? shopperLocale;
final String? shopperReference;
final String? storePaymentMethodMode;
final String? recurringProcessingModel;
final String? shopperInteraction;
final String? channel;
final String? telephoneNumber;
final String? dateOfBirth;
final String? socialSecurityNumber;
final DeliveryAddress? deliveryAddress;
final BillingAddress? billingAddress;
final List<LineItem>? lineItems;

SessionRequestNetworkModel({
required this.merchantAccount,
required this.amount,
required this.returnUrl,
required this.reference,
required this.countryCode,
this.shopperLocale,
this.shopperReference,
this.storePaymentMethodMode,
this.recurringProcessingModel,
this.shopperInteraction,
this.channel,
this.telephoneNumber,
this.dateOfBirth,
this.socialSecurityNumber,
this.deliveryAddress,
this.billingAddress,
this.lineItems,
});

String toRawJson() => json.encode(toJson());
Expand All @@ -34,10 +53,19 @@ class SessionRequestNetworkModel {
data['returnUrl'] = returnUrl;
data['reference'] = reference;
data['countryCode'] = countryCode;
data['shopperLocale'] = shopperLocale;
data['shopperReference'] = shopperReference;
data['storePaymentMethodMode'] = storePaymentMethodMode;
data['recurringProcessingModel'] = recurringProcessingModel;
data['shopperInteraction'] = shopperInteraction;
data['channel'] = channel;
data['telephoneNumber'] = telephoneNumber;
data['dateOfBirth'] = dateOfBirth;
data['socialSecurityNumber'] = socialSecurityNumber;
data['billingAddress'] = billingAddress?.toJson();
data['deliveryAddress'] = deliveryAddress?.toJson();
data['lineItems'] =
lineItems?.map((lineItem) => lineItem.toJson()).toList();
return data;
}
}
Expand All @@ -54,6 +82,13 @@ enum RecurringProcessingModel {
unscheduledCardOnFile
}

enum ShopperInteractionModel {
ecommerce,
contAuth,
moto,
pos
}

extension StorePaymentMethodModeExtension on StorePaymentMethodMode {
String get storePaymentMethodModeString {
switch (this) {
Expand All @@ -79,3 +114,18 @@ extension RecurringProcessingModelExtension on RecurringProcessingModel {
}
}
}

extension ShopperInteractionModelExtension on ShopperInteractionModel {
String get shopperInteractionModelString {
switch (this) {
case ShopperInteractionModel.ecommerce:
return "Ecommerce";
case ShopperInteractionModel.contAuth:
return "ContAuth";
case ShopperInteractionModel.moto:
return "Moto";
case ShopperInteractionModel.pos:
return "POS";
}
}
}
Loading