BTThreeDSecureResult.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #import "BTThreeDSecureResult_Internal.h"
  2. #import "BTThreeDSecureLookup_Internal.h"
  3. #if __has_include(<Braintree/BraintreeThreeDSecure.h>) // CocoaPods
  4. #import <Braintree/BraintreeCore.h>
  5. #import <Braintree/BTCardNonce_Internal.h>
  6. #elif SWIFT_PACKAGE // SPM
  7. #import <BraintreeCore/BraintreeCore.h>
  8. #import "../BraintreeCard/BTCardNonce_Internal.h"
  9. #else // Carthage
  10. #import <BraintreeCore/BraintreeCore.h>
  11. #import <BraintreeCard/BTCardNonce_Internal.h>
  12. #endif
  13. @implementation BTThreeDSecureResult
  14. - (instancetype)initWithJSON:(BTJSON *)json {
  15. self = [super init];
  16. if (self) {
  17. if ([json[@"paymentMethod"] asDictionary]) {
  18. _tokenizedCard = [BTCardNonce cardNonceWithJSON:json[@"paymentMethod"]];
  19. }
  20. if ([json[@"lookup"] asDictionary]) {
  21. _lookup = [[BTThreeDSecureLookup alloc] initWithJSON:json[@"lookup"]];
  22. }
  23. if ([json[@"errors"] asArray]) {
  24. NSDictionary *firstError = (NSDictionary *)[json[@"errors"] asArray].firstObject;
  25. if (firstError[@"message"]) {
  26. _errorMessage = [firstError[@"message"] asString];
  27. }
  28. } else {
  29. _errorMessage = [json[@"error"][@"message"] asString];
  30. }
  31. }
  32. return self;
  33. }
  34. @end