PPOTRequest.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // PPOTRequest.h
  3. //
  4. // Copyright © 2015 PayPal, Inc. All rights reserved.
  5. //
  6. #import <Foundation/Foundation.h>
  7. #import "PPOTResult.h"
  8. /**
  9. Completion block for receiving the result of preflighting a request
  10. */
  11. typedef void (^PPOTRequestPreflightCompletionBlock) (PPOTRequestTarget target);
  12. /**
  13. Adapter block for app switching.
  14. */
  15. typedef void (^PPOTRequestAdapterBlock) (BOOL success, NSURL * _Nonnull url, PPOTRequestTarget target, NSString * _Nullable clientMetadataId, NSError * _Nullable error);
  16. /**
  17. This environment MUST be used for App Store submissions.
  18. */
  19. extern NSString * _Nonnull const PayPalEnvironmentProduction;
  20. /**
  21. Sandbox: Uses the PayPal sandbox for transactions. Useful for development.
  22. */
  23. extern NSString * _Nonnull const PayPalEnvironmentSandbox;
  24. /**
  25. Mock: Mock mode. Does not submit transactions to PayPal. Fakes successful responses. Useful for unit tests.
  26. */
  27. extern NSString * _Nonnull const PayPalEnvironmentMock;
  28. /**
  29. Base class for all One Touch requests
  30. */
  31. @interface PPOTRequest : NSObject
  32. /**
  33. Optional preflight method, to determine in advance to which app we will switch when this request's `performWithCompletionBlock:` method is called.
  34. @note As currently implemented, `completionBlock` will be called synchronously.
  35. We use a completion block here to allow for future changes in implementation that might cause
  36. delays (such as time-consuming cryptographic operations, or server interactions).
  37. */
  38. - (void)getTargetApp:(nullable PPOTRequestPreflightCompletionBlock)completionBlock;
  39. /**
  40. Ask the One Touch library to carry out a request.
  41. Will app switch to the PayPal Wallet app if present, or to the mobile browser otherwise.
  42. @param adapterBlock Block that makes the URL request.
  43. @note The adapter block is responsible for determining which app to app switch to (Wallet, browser, or neither).
  44. The `completionBlock` is called synchronously.
  45. We use a completion block here to allow for future changes in implementation that might cause
  46. delays (such as time-consuming cryptographic operations, or server interactions).
  47. */
  48. - (void)performWithAdapterBlock:(nullable PPOTRequestAdapterBlock)adapterBlock;
  49. /**
  50. Get token from approval URL
  51. */
  52. + (nullable NSString *)tokenFromApprovalURL:(nonnull NSURL *)approvalURL;
  53. /**
  54. All requests MUST include the app's Client ID, as obtained from developer.paypal.com
  55. */
  56. @property (nonnull, nonatomic, readonly) NSString *clientID;
  57. /**
  58. All requests MUST indicate the environment -
  59. `PayPalEnvironmentProduction`, `PayPalEnvironmentMock`, or `PayPalEnvironmentSandbox`;
  60. or else a stage indicated as `base-url:port`
  61. */
  62. @property (nonnull, nonatomic, readonly) NSString *environment;
  63. /**
  64. All requests MUST indicate the URL scheme to be used for returning to this app, following an app switch
  65. */
  66. @property (nonnull, nonatomic, readonly) NSString *callbackURLScheme;
  67. /**
  68. Requests MAY include additional key/value pairs that One Touch will add to the payload
  69. (For example, the Braintree client_token, which is required by the temporary Braintree Future Payments consent webpage.)
  70. */
  71. @property (nonnull, nonatomic, strong) NSDictionary *additionalPayloadAttributes;
  72. #ifdef DEBUG
  73. /**
  74. DEBUG-only: don't use downloaded configuration file; defaults to NO
  75. */
  76. @property (nonatomic, assign, readwrite) BOOL useHardcodedConfiguration;
  77. #endif
  78. @end
  79. /**
  80. Request consent for Profile Sharing (e.g., for Future Payments)
  81. */
  82. @interface PPOTAuthorizationRequest : PPOTRequest
  83. /**
  84. Set of requested scope-values.
  85. Available scope-values are listed at https://developer.paypal.com/webapps/developer/docs/integration/direct/identity/attributes/
  86. */
  87. @property (nonnull, nonatomic, readonly) NSSet *scopeValues;
  88. /**
  89. The URL of the merchant's privacy policy
  90. */
  91. @property (nonnull, nonatomic, readonly) NSURL *privacyURL;
  92. /**
  93. The URL of the merchant's user agreement
  94. */
  95. @property (nonnull, nonatomic, readonly) NSURL *agreementURL;
  96. @end
  97. /**
  98. Request approval of a payment
  99. */
  100. @interface PPOTCheckoutRequest : PPOTRequest
  101. @property (nonnull, nonatomic, strong) NSString *pairingId;
  102. /**
  103. Client has already created a payment on PayPal server; this is the resulting HATEOS ApprovalURL
  104. */
  105. @property (nonnull, nonatomic, readonly) NSURL *approvalURL;
  106. @end
  107. /**
  108. Request approval of a Billing Agreement
  109. */
  110. @interface PPOTBillingAgreementRequest : PPOTCheckoutRequest
  111. @end