BTTokenizationService.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #import <Foundation/Foundation.h>
  2. #import "BTAPIClient.h"
  3. #import "BTPaymentMethodNonce.h"
  4. NS_ASSUME_NONNULL_BEGIN
  5. /**
  6. Domain for tokenization service errors.
  7. */
  8. extern NSString * const BTTokenizationServiceErrorDomain;
  9. /**
  10. Key for app switch delegate.
  11. */
  12. extern NSString * const BTTokenizationServiceAppSwitchDelegateOption;
  13. /**
  14. Key for view presenting delegate.
  15. */
  16. extern NSString * const BTTokenizationServiceViewPresentingDelegateOption;
  17. /**
  18. Key for PayPal scopes.
  19. */
  20. extern NSString * const BTTokenizationServicePayPalScopesOption;
  21. /**
  22. Key for amount.
  23. */
  24. extern NSString * const BTTokenizationServiceAmountOption;
  25. /**
  26. Key for nonce.
  27. */
  28. extern NSString * const BTTokenizationServiceNonceOption;
  29. /**
  30. Error codes associated with `BTTokenizationService`.
  31. */
  32. typedef NS_ENUM(NSInteger, BTTokenizationServiceError) {
  33. /// Unknown error
  34. BTTokenizationServiceErrorUnknown = 0,
  35. /// Type not registered
  36. BTTokenizationServiceErrorTypeNotRegistered,
  37. };
  38. /**
  39. A tokenization service that supports registration of tokenizers at runtime.
  40. `BTTokenizationService` provides access to tokenization services from payment options
  41. (e.g. `BTPayPalDriver`) without introducing compile-time dependencies on the frameworks.
  42. */
  43. @interface BTTokenizationService : NSObject
  44. /**
  45. The singleton instance of the tokenization service
  46. */
  47. + (instancetype)sharedService;
  48. /**
  49. Registers a block to execute for a given type when `tokenizeType:withAPIClient:completion:` or`tokenizeType:options:withAPIClient:completion:` are invoked.
  50. @param type A type string to identify the tokenization block. Providing a type that has already
  51. been registered will overwrite the previously registered tokenization block.
  52. @param tokenizationBlock The tokenization block to register for a type.
  53. */
  54. - (void)registerType:(NSString *)type withTokenizationBlock:(void(^)(BTAPIClient *apiClient, NSDictionary * _Nullable options, void(^)(BTPaymentMethodNonce * _Nullable paymentMethodNonce, NSError * _Nullable error)))tokenizationBlock;
  55. /**
  56. Indicates whether a type has been registered with a valid tokenization block.
  57. */
  58. - (BOOL)isTypeAvailable:(NSString *)type;
  59. /**
  60. Perform tokenization for the given type. This will execute the tokenization block that has been registered for the type.
  61. @param type The tokenization type to perform
  62. @param apiClient The API client to use when performing tokenization.
  63. @param completion The completion block to invoke when tokenization has completed.
  64. */
  65. - (void)tokenizeType:(NSString *)type
  66. withAPIClient:(BTAPIClient *)apiClient
  67. completion:(void(^)(BTPaymentMethodNonce * _Nullable paymentMethodNonce, NSError * _Nullable error))completion;
  68. /**
  69. Perform tokenization for the given type. This will execute the tokenization block that has been registered for the type.
  70. @param type The tokenization type to perform
  71. @param options A dictionary of data to use when invoking the tokenization block. This can be
  72. used to pass data into a tokenization client/driver, e.g. credit card raw details.
  73. @param apiClient The API client to use when performing tokenization.
  74. @param completion The completion block to invoke when tokenization has completed.
  75. */
  76. - (void)tokenizeType:(NSString *)type
  77. options:(nullable NSDictionary<NSString *, id> *)options
  78. withAPIClient:(BTAPIClient *)apiClient
  79. completion:(void(^)(BTPaymentMethodNonce * _Nullable paymentMethodNonce, NSError * _Nullable error))completion;
  80. /**
  81. An array of all tokenization types
  82. */
  83. @property (nonatomic, readonly, strong) NSArray <NSString *> *allTypes;
  84. @end
  85. NS_ASSUME_NONNULL_END