BTPaymentMethodNonceParser.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #import <Foundation/Foundation.h>
  2. @class BTJSON;
  3. @class BTPaymentMethodNonce;
  4. NS_ASSUME_NONNULL_BEGIN
  5. /**
  6. A JSON parser that parses `BTJSON` into concrete `BTPaymentMethodNonce` objects. It supports registration of parsers at runtime.
  7. `BTPaymentMethodNonceParser` provides access to JSON parsing for different payment options
  8. without introducing compile-time dependencies on payment option frameworks and their symbols.
  9. */
  10. @interface BTPaymentMethodNonceParser : NSObject
  11. /**
  12. The singleton instance
  13. */
  14. + (instancetype)sharedParser;
  15. /**
  16. An array of the tokenization types currently registered
  17. */
  18. @property (nonatomic, readonly, strong) NSArray<NSString *> *allTypes;
  19. /**
  20. Indicates whether a tokenization type is currently registered
  21. @param type The tokenization type string
  22. */
  23. - (BOOL)isTypeAvailable:(NSString *)type;
  24. /**
  25. Registers a parsing block for a tokenization type.
  26. @param type The tokenization type string
  27. @param jsonParsingBlock The block to execute when `parseJSON:type:` is called for the tokenization type.
  28. This block should return a `BTPaymentMethodNonce` object, or `nil` if the JSON cannot be parsed.
  29. */
  30. - (void)registerType:(NSString *)type withParsingBlock:(BTPaymentMethodNonce * _Nullable (^)(BTJSON *json))jsonParsingBlock;
  31. /**
  32. Parses tokenized payment information that has been serialized to JSON, and returns a `BTPaymentMethodNonce` object.
  33. The `BTPaymentMethodNonce` object is created by the JSON parsing block that has been registered for the tokenization
  34. type.
  35. If the `type` has not been registered, this method will attempt to read the nonce from the JSON and return
  36. a basic object; if it fails, it will return `nil`.
  37. @param json The tokenized payment info, serialized to JSON
  38. @param type The registered type of the parsing block to use
  39. @return A `BTPaymentMethodNonce` object, or `nil` if the tokenized payment info JSON does not contain a nonce
  40. */
  41. - (nullable BTPaymentMethodNonce *)parseJSON:(BTJSON *)json withParsingBlockForType:(NSString *)type;
  42. @end
  43. NS_ASSUME_NONNULL_END