Adyen / adyen-flutter

MIT License
23 stars 4 forks source link

PaymentResult and its implementations should extends Equatable #153

Closed Cteq3132 closed 2 months ago

Cteq3132 commented 4 months ago

Describe the bug The class PaymentResult and all its implementation are not comparable. In Flutter, classes must extend Equatable to be able to compare object between them. Not doing so produces the following result:

final resultA = PaymentAdvancedFinished(resultCode = "Accepted");
final resultB = PaymentAdvancedFinished(resultCode = "Accepted");

print(resultA == resultB); // => false

To Reproduce See above.

Expected behavior Class comparison implementation.

Screenshots /

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

Robert-SD commented 4 months ago

Hello @Cteq3132, thanks again for bringing up this topic! I'm currently hesitant to introduce the equatable dependency to the SDK because the amount of dependencies should be kept at a minimum. However, let's discuss this potential change. Could you explain your use case for the comparison?

Would it be possible to implement a custom class that extends equatable on your app level? For example this is what I thought about:

class EquatablePaymentAdvancedFinished extends Equatable {
  final PaymentAdvancedFinished paymentAdvancedFinished;

  const EquatablePaymentAdvancedFinished(
      {required this.paymentAdvancedFinished});

  @override
  List<Object?> get props => [paymentAdvancedFinished.resultCode];
}

And then mapping the payment result

 if (paymentResult is PaymentAdvancedFinished) {
      final EquatablePaymentAdvancedFinished equatablePaymentAdvancedFinished =
          EquatablePaymentAdvancedFinished(paymentAdvancedFinished: paymentResult);
 }

This would be the corresponding test:

  test("Equatable test", () {
    final resultA = PaymentAdvancedFinished(resultCode: "Accepted");
    final resultB = PaymentAdvancedFinished(resultCode: "Accepted");
    final nonEquatable = resultA == resultB;
    expect(nonEquatable, false);

    final resultC = EquatablePaymentAdvancedFinished(paymentAdvancedFinished: resultA);
    final resultD = EquatablePaymentAdvancedFinished(paymentAdvancedFinished: resultB);
    final equatable = resultC == resultD;
    expect(equatable, true);
  });

Please let me know if this might be a solution for introducing equatable for you.

Robert-SD commented 2 months ago

Hi @Cteq3132, we will close this issue. Please feel free to open it again, if you have any additional questions.