BTThreeDSecureResult.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #import "BTThreeDSecureResult.h"
  2. #if __has_include("BraintreeCard.h")
  3. #import "BTCardNonce_Internal.h"
  4. #else
  5. #import <BraintreeCard/BTCardNonce_Internal.h>
  6. #endif
  7. @implementation BTThreeDSecureResult
  8. - (instancetype)initWithJSON:(BTJSON *)json {
  9. self = [super init];
  10. if (self) {
  11. if (json[@"paymentMethod"]) {
  12. _tokenizedCard = [BTCardNonce cardNonceWithJSON:json[@"paymentMethod"]];
  13. }
  14. if ([json[@"errors"] asArray]) {
  15. NSDictionary *firstError = (NSDictionary *)[json[@"errors"] asArray].firstObject;
  16. if (firstError[@"message"]) {
  17. _errorMessage = firstError[@"message"];
  18. }
  19. } else {
  20. _errorMessage = [json[@"error"][@"message"] asString];
  21. }
  22. _liabilityShifted = [json[@"threeDSecureInfo"][@"liabilityShifted"] isTrue];
  23. _liabilityShiftPossible = [json[@"threeDSecureInfo"][@"liabilityShiftPossible"] isTrue];
  24. // Account for absence of "success" key in 2.0 gateway responses
  25. if ([json[@"success"] isBool]) {
  26. _success = [json[@"success"] isTrue];
  27. } else {
  28. _success = _errorMessage == nil;
  29. }
  30. }
  31. return self;
  32. }
  33. - (NSString *)debugDescription {
  34. return [NSString stringWithFormat:@"<BTThreeDSecureResult: %p errorMessage:%@>", self, self.tokenizedCard.threeDSecureInfo.errorMessage];
  35. }
  36. @end