PPOTBillingAgreementRequest.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PPOTBillingAgreementRequest.m
  3. // PayPalOneTouch
  4. //
  5. // Copyright © 2015 PayPal, Inc. All rights reserved.
  6. //
  7. #import "PPOTRequest_Internal.h"
  8. #import "PPOTCheckoutAppSwitchRequest.h"
  9. #import "PPOTCheckoutBrowserSwitchRequest.h"
  10. #import "PPOTConfiguration.h"
  11. #if __has_include("PayPalUtils.h")
  12. #import "PPOTDevice.h"
  13. #import "PPOTMacros.h"
  14. #else
  15. #import <PayPalUtils/PPOTDevice.h>
  16. #import <PayPalUtils/PPOTMacros.h>
  17. #endif
  18. #pragma mark - PPOTBillingAgreementRequest implementation
  19. @implementation PPOTBillingAgreementRequest
  20. #pragma mark - add subclass-specific info to appSwitchRequest
  21. - (PPOTSwitchRequest *)getAppSwitchRequestForConfigurationRecipe:(PPOTConfigurationRecipe *)configurationRecipe {
  22. PPOTCheckoutSwitchRequest *appSwitchRequest = nil;
  23. switch (configurationRecipe.target) {
  24. case PPOTRequestTargetOnDeviceApplication: {
  25. appSwitchRequest = [[PPOTCheckoutAppSwitchRequest alloc] initWithProtocolVersion:configurationRecipe.protocolVersion
  26. appGuid:[PPOTDevice appropriateIdentifier]
  27. clientID:self.clientID
  28. environment:self.environment
  29. callbackURLScheme:self.callbackURLScheme
  30. pairingId:self.pairingId];
  31. break;
  32. }
  33. case PPOTRequestTargetBrowser: {
  34. PPOTCheckoutBrowserSwitchRequest *browserSwitchRequest =
  35. [[PPOTCheckoutBrowserSwitchRequest alloc] initWithProtocolVersion:configurationRecipe.protocolVersion
  36. appGuid:[PPOTDevice appropriateIdentifier]
  37. clientID:self.clientID
  38. environment:self.environment
  39. callbackURLScheme:self.callbackURLScheme
  40. pairingId:self.pairingId];
  41. appSwitchRequest = browserSwitchRequest;
  42. break;
  43. }
  44. default: {
  45. break;
  46. }
  47. }
  48. if (appSwitchRequest) {
  49. appSwitchRequest.targetAppURLScheme = configurationRecipe.targetAppURLScheme;
  50. appSwitchRequest.responseType = PPAppSwitchResponseTypeWeb;
  51. appSwitchRequest.approvalURL = [self.approvalURL absoluteString];
  52. }
  53. return appSwitchRequest;
  54. }
  55. #pragma mark - configuration methods
  56. - (void)getAppropriateConfigurationRecipe:(void (^)(PPOTConfigurationRecipe *configurationRecipe))completionBlock {
  57. PPAssert(completionBlock, @"getAppropriateConfigurationRecipe: completionBlock is required");
  58. PPOTConfiguration *currentConfiguration = [PPOTConfiguration getCurrentConfiguration];
  59. PPOTConfigurationBillingAgreementRecipe *bestConfigurationRecipe = nil;
  60. for (PPOTConfigurationBillingAgreementRecipe *configurationRecipe in currentConfiguration.prioritizedBillingAgreementRecipes) {
  61. if (![self isConfigurationRecipeTargetSupported:configurationRecipe] ||
  62. ![self isConfigurationRecipeLocaleSupported:configurationRecipe]) {
  63. continue;
  64. }
  65. bestConfigurationRecipe = configurationRecipe;
  66. break;
  67. }
  68. completionBlock(bestConfigurationRecipe);
  69. }
  70. @end