Skip to content

Commit 2ed91fc

Browse files
support for paymentAttemptId (#52)
* remove idempotencyKey * left deprecated method
1 parent 9fb5a94 commit 2ed91fc

File tree

6 files changed

+1029
-71
lines changed

6 files changed

+1029
-71
lines changed

android/src/main/kotlin/com/squareup/square_mobile_payments_sdk/modules/SettingsModule.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ class SettingsModule {
6464
result.success(consentState.name)
6565
}
6666
@JvmStatic
67-
@JvmStatic
6867
fun updateTrackingConsent(result: MethodChannel.Result, granted: Boolean) {
69-
settingsManager.updateTrackingConsent(granted) // Assuming the method name is similar
68+
settingsManager.updateTrackingConsent(granted)
7069
result.success(true)
7170
}
7271

example/lib/donut_counter_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class _DonutCounterScreenState extends State<DonutCounterScreen> {
2121

2222
_onBuy(BuildContext context, int amount) async {
2323
try {
24-
String idempotencyKey = uuid.v4();
24+
String paymentAttemptId = uuid.v4();
2525

2626
Payment payment = await _squareMobilePaymentsSdkPlugin.paymentManager
2727
.startPayment(
2828
PaymentParameters(
2929
processingMode: 0,
3030
amountMoney:
3131
Money(amount: amount, currencyCode: CurrencyCode.eur),
32-
idempotencyKey: idempotencyKey),
32+
paymentAttemptId: paymentAttemptId),
3333
PromptParameters(
3434
additionalPaymentMethods: List.empty(),
3535
mode: PromptMode.defaultMode));

ios/Classes/Mappers/PaymentMapper.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class PaymentMapper {
2020
let amountMoney = paymentParameters["amountMoney"] as? [String: Any],
2121
let amount = amountMoney["amount"] as? UInt,
2222
let currencyCode = amountMoney["currencyCode"] as? String,
23-
let idempotencyKey = paymentParameters["idempotencyKey"] as? String,
2423
let processingMode = paymentParameters["processingMode"] as? Int
2524
else {
2625
fatalError("Error: Missing or invalid required payment parameters")
@@ -32,13 +31,26 @@ public class PaymentMapper {
3231
// Create the amountMoney object
3332
let money = Money(amount: amount, currency: currency)
3433

35-
// Initialize PaymentParameters with required fields
36-
var paymentParams = PaymentParameters(
37-
idempotencyKey: idempotencyKey,
38-
amountMoney: money,
39-
processingMode: ProcessingMode(rawValue: processingMode)!
40-
)
34+
var paymentParams: PaymentParameters? = nil
35+
if let paymentAttemptID = paymentParameters["paymentAttemptId"] as? String{
36+
paymentParams = PaymentParameters(
37+
paymentAttemptID: paymentAttemptID,
38+
amountMoney: money,
39+
processingMode: ProcessingMode(rawValue: processingMode)!
40+
)
41+
}
42+
else if let idempotencyKey = paymentParameters["idempotencyKey"] as? String {
43+
paymentParams = PaymentParameters(
44+
idempotencyKey: idempotencyKey,
45+
amountMoney: money,
46+
processingMode: ProcessingMode(rawValue: processingMode)!
47+
)
48+
}
4149

50+
guard let paymentParams
51+
else {
52+
fatalError("Error: Missing or invalid required payment parameters")
53+
}
4254
// Optional: appFeeMoney
4355
if let appFeeMoney = paymentParameters["appFeeMoney"] as? [String: Any],
4456
let appFeeAmount = appFeeMoney["amount"] as? UInt,

lib/src/models/models.dart

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,49 @@ class Payment with _$Payment {
191191
_$PaymentFromJson(json);
192192
}
193193

194-
@freezed
194+
@Freezed(unionKey: 'type') // 👈 needed because we have two constructors
195195
class PaymentParameters with _$PaymentParameters {
196+
/// ✅ Current / recommended constructor
197+
@FreezedUnionValue('current')
196198
const factory PaymentParameters({
197199
int? acceptPartialAuthorization,
198200
required Money amountMoney,
199-
Money? appFeeMoney,
200-
bool? autocomplete,
201-
String? customerId,
202-
DelayAction? delayAction,
203-
num? delayDuration,
204-
required num processingMode,
205-
String? idempotencyKey,
206-
String? paymentAttemptId,
207-
String? locationId,
201+
Money? appFeeMoney,
202+
bool? autocomplete,
203+
String? customerId,
204+
DelayAction? delayAction,
205+
num? delayDuration,
206+
required num processingMode,
207+
required String paymentAttemptId,
208+
String? locationId,
208209
String? note,
209-
String? orderId,
210-
String? referenceId,
211-
String? teamMemberId,
212-
Money? tipMoney,
210+
String? orderId,
211+
String? referenceId,
212+
String? teamMemberId,
213+
Money? tipMoney,
213214
}) = _PaymentParameters;
214215

216+
/// ⚠️ Deprecated constructor
217+
@Deprecated('Use the constructor with paymentAttemptId instead.')
218+
@FreezedUnionValue('legacy')
219+
const factory PaymentParameters.legacy({
220+
int? acceptPartialAuthorization,
221+
required Money amountMoney,
222+
Money? appFeeMoney,
223+
bool? autocomplete,
224+
String? customerId,
225+
DelayAction? delayAction,
226+
num? delayDuration,
227+
required num processingMode,
228+
required String idempotencyKey,
229+
String? locationId,
230+
String? note,
231+
String? orderId,
232+
String? referenceId,
233+
String? teamMemberId,
234+
Money? tipMoney,
235+
}) = _LegacyPaymentParameters;
236+
215237
factory PaymentParameters.fromJson(Map<String, Object?> json) =>
216238
_$PaymentParametersFromJson(json);
217239
}

0 commit comments

Comments
 (0)