Skip to content

Commit

Permalink
Adjusted cash app pay configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Sep 20, 2023
1 parent 4861aa2 commit 8daacb1
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,22 @@ data class GooglePayConfigurationDTO (

/** Generated class from Pigeon that represents data sent in messages. */
data class CashAppPayConfigurationDTO (
val cashAppPayEnvironment: CashAppPayEnvironment
val cashAppPayEnvironment: CashAppPayEnvironment,
val returnUrl: String

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): CashAppPayConfigurationDTO {
val cashAppPayEnvironment = CashAppPayEnvironment.ofRaw(list[0] as Int)!!
return CashAppPayConfigurationDTO(cashAppPayEnvironment)
val returnUrl = list[1] as String
return CashAppPayConfigurationDTO(cashAppPayEnvironment, returnUrl)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
cashAppPayEnvironment.raw,
returnUrl,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ object Mapper {
}

private fun CashAppPayConfigurationDTO.mapToCashAppPayConfiguration(builder: CashAppPayConfiguration.Builder): CashAppPayConfiguration {
builder.setCashAppPayEnvironment(cashAppPayEnvironment.mapToCashAppPayEnvironment())
return builder.build();
builder
.setCashAppPayEnvironment(cashAppPayEnvironment.mapToCashAppPayEnvironment())
.setReturnUrl(returnUrl)
return builder.build()
}

private fun CashAppPayEnvironment.mapToCashAppPayEnvironment(): SDKCashAppPayEnvironment {
Expand Down
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class _MyAppState extends State<MyApp> {
Config.amount,
Config.environment,
);

final DropInConfiguration dropInConfiguration = DropInConfiguration(
environment: Environment.test,
clientKey: Config.clientKey,
Expand All @@ -107,6 +108,8 @@ class _MyAppState extends State<MyApp> {
Future<PaymentResult> startDropInAdvancedFlow() async {
final String paymentMethodsResponse =
await _adyenSessionRepository.fetchPaymentMethods();
final String returnUrl =
await _adyenSessionRepository.determineExampleReturnUrl();

final CardsConfiguration cardsConfiguration = CardsConfiguration(
holderNameRequired: true,
Expand All @@ -125,6 +128,12 @@ class _MyAppState extends State<MyApp> {
shippingAddressRequired: true,
);

final CashAppPayConfiguration cashAppPayConfiguration =
CashAppPayConfiguration(
CashAppPayEnvironment.sandbox,
returnUrl,
);

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

return await _adyenCheckout.startPayment(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/repositories/adyen_sessions_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AdyenSessionsRepository {
//A session should not being created from the mobile application.
//Please provide a CheckoutSession object from your own backend.
Future<Session> createSession(Amount amount, Environment environment) async {
String returnUrl = await _determineExampleReturnUrl();
String returnUrl = await determineExampleReturnUrl();
SessionRequestNetworkModel sessionRequestNetworkModel =
SessionRequestNetworkModel(
merchantAccount: Config.merchantAccount,
Expand Down Expand Up @@ -55,7 +55,7 @@ class AdyenSessionsRepository {
}

Future<DropInOutcome> postPayments(String paymentComponentJson) async {
String returnUrl = await _determineExampleReturnUrl();
String returnUrl = await determineExampleReturnUrl();
PaymentsRequestData paymentsRequestData = PaymentsRequestData(
merchantAccount: Config.merchantAccount,
shopperReference: Config.shopperReference,
Expand Down Expand Up @@ -87,7 +87,7 @@ class AdyenSessionsRepository {
return _dropInOutcomeHandler.handleResponse(response);
}

Future<String> _determineExampleReturnUrl() async {
Future<String> determineExampleReturnUrl() async {
if (Platform.isAndroid) {
return await _adyenCheckout.getReturnUrl();
} else if (Platform.isIOS) {
Expand Down
3 changes: 1 addition & 2 deletions ios/Classes/CheckoutPlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface {
}

if let cashAppPayConfigurationDTO = dropInConfigurationDTO.cashAppPayConfigurationDTO {
let cashAppPayConfiguration = DropInComponent.CashAppPay.init(redirectURL: try URL(from: "test" as! Decoder))
dropInConfiguration.cashAppPay = cashAppPayConfiguration
dropInConfiguration.cashAppPay = DropInComponent.CashAppPay(redirectURL: URL(string: cashAppPayConfigurationDTO.returnUrl)!)
}

return dropInConfiguration
Expand Down
6 changes: 5 additions & 1 deletion ios/Classes/PlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,21 @@ struct GooglePayConfigurationDTO {
/// Generated class from Pigeon that represents data sent in messages.
struct CashAppPayConfigurationDTO {
var cashAppPayEnvironment: CashAppPayEnvironment
var returnUrl: String

static func fromList(_ list: [Any?]) -> CashAppPayConfigurationDTO? {
let cashAppPayEnvironment = CashAppPayEnvironment(rawValue: list[0] as! Int)!
let returnUrl = list[1] as! String

return CashAppPayConfigurationDTO(
cashAppPayEnvironment: cashAppPayEnvironment
cashAppPayEnvironment: cashAppPayEnvironment,
returnUrl: returnUrl
)
}
func toList() -> [Any?] {
return [
cashAppPayEnvironment.rawValue,
returnUrl,
]
}
}
Expand Down
5 changes: 3 additions & 2 deletions ios/Classes/dropInSessions/DropInSessionsDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Adyen
import AdyenNetworking

class DropInSessionsDelegate : AdyenSessionDelegate {

private let viewController : UIViewController?
private let checkoutFlutterApi: CheckoutFlutterApi

Expand All @@ -10,9 +11,9 @@ class DropInSessionsDelegate : AdyenSessionDelegate {
self.checkoutFlutterApi = checkoutFlutterApi
}

func didComplete(with resultCode: SessionPaymentResultCode, component: Component, session: AdyenSession) {
func didComplete(with result: Adyen.AdyenSessionResult, component: Adyen.Component, session: Adyen.AdyenSession) {
viewController?.dismiss(animated: false, completion: {
let paymentResult = PaymentResultModel(sessionId: session.sessionContext.identifier, sessionData: session.sessionContext.data, resultCode: resultCode.rawValue)
let paymentResult = PaymentResultModel(sessionId: session.sessionContext.identifier, sessionData: session.sessionContext.data, resultCode: result.resultCode.rawValue)
self.checkoutFlutterApi.onDropInSessionResult(sessionPaymentResult: PaymentResult(type: PaymentResultEnum.finished, result: paymentResult), completion: {})
})
}
Expand Down
1 change: 1 addition & 0 deletions ios/adyen_checkout.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Adyen checkout SDK for Flutter
s.swift_version = '5.0'

s.dependency 'Adyen', '5.3.0'
s.dependency 'Adyen/CashAppPay'
end
2 changes: 2 additions & 0 deletions lib/adyen_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export 'src/models/drop_in_outcome.dart';
export 'src/models/payment_flow.dart';
export 'src/models/payment_method_configurations/apple_pay_configuration.dart';
export 'src/models/payment_method_configurations/cards_configuration.dart';
export 'src/models/payment_method_configurations/cash_app_pay_configuration.dart';
export 'src/models/payment_method_configurations/google_pay_configuration.dart';

4 changes: 4 additions & 0 deletions lib/src/adyen_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class AdyenCheckout implements AdyenCheckoutInterface {
dropInSession.dropInConfiguration.applePayConfigurationDTO,
googlePayConfigurationDTO:
dropInSession.dropInConfiguration.googlePayConfigurationDTO,
cashAppPayConfigurationDTO:
dropInSession.dropInConfiguration.cashAppPayConfigurationDTO,
analyticsOptionsDTO:
dropInSession.dropInConfiguration.analyticsOptionsDTO,
);
Expand Down Expand Up @@ -74,6 +76,8 @@ class AdyenCheckout implements AdyenCheckoutInterface {
dropInAdvancedFlow.dropInConfiguration.applePayConfigurationDTO,
googlePayConfigurationDTO:
dropInAdvancedFlow.dropInConfiguration.googlePayConfigurationDTO,
cashAppPayConfigurationDTO:
dropInAdvancedFlow.dropInConfiguration.cashAppPayConfigurationDTO,
analyticsOptionsDTO:
dropInAdvancedFlow.dropInConfiguration.analyticsOptionsDTO,
);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/generated/platform_api.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,25 @@ class GooglePayConfigurationDTO {
class CashAppPayConfigurationDTO {
CashAppPayConfigurationDTO({
required this.cashAppPayEnvironment,
required this.returnUrl,
});

CashAppPayEnvironment cashAppPayEnvironment;

String returnUrl;

Object encode() {
return <Object?>[
cashAppPayEnvironment.index,
returnUrl,
];
}

static CashAppPayConfigurationDTO decode(Object result) {
result as List<Object?>;
return CashAppPayConfigurationDTO(
cashAppPayEnvironment: CashAppPayEnvironment.values[result[0]! as int],
returnUrl: result[1]! as String,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import 'package:adyen_checkout/src/generated/platform_api.g.dart';

class CashAppPayConfiguration {
final CashAppPayEnvironment cashAppPayEnvironment;
final String returnUrl;

CashAppPayConfiguration(this.cashAppPayEnvironment);
CashAppPayConfiguration(
this.cashAppPayEnvironment,
this.returnUrl,
);
}
2 changes: 1 addition & 1 deletion lib/src/utils/dto_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:adyen_checkout/src/generated/platform_api.g.dart';
import 'package:adyen_checkout/src/models/analytics_options.dart';
import 'package:adyen_checkout/src/models/payment_method_configurations/cash_app_pay_configuration.dart';

extension AnalyticsOptionsMapper on AnalyticsOptions {
AnalyticsOptionsDTO toDTO() => AnalyticsOptionsDTO(
Expand Down Expand Up @@ -51,5 +50,6 @@ extension ApplePayConfigurationMapper on ApplePayConfiguration {
extension CashAppPayConfigurationMapper on CashAppPayConfiguration {
CashAppPayConfigurationDTO toDTO() => CashAppPayConfigurationDTO(
cashAppPayEnvironment: cashAppPayEnvironment,
returnUrl: returnUrl,
);
}
6 changes: 5 additions & 1 deletion pigeons/platform_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ class GooglePayConfigurationDTO {

class CashAppPayConfigurationDTO {
final CashAppPayEnvironment cashAppPayEnvironment;
final String returnUrl;

CashAppPayConfigurationDTO(this.cashAppPayEnvironment);
CashAppPayConfigurationDTO(
this.cashAppPayEnvironment,
this.returnUrl,
);
}

class PaymentResult {
Expand Down

0 comments on commit 8daacb1

Please sign in to comment.