| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // PPOTBillingAgreementRequest.m
- // PayPalOneTouch
- //
- // Copyright © 2015 PayPal, Inc. All rights reserved.
- //
- #import "PPOTRequest_Internal.h"
- #import "PPOTCheckoutAppSwitchRequest.h"
- #import "PPOTCheckoutBrowserSwitchRequest.h"
- #import "PPOTConfiguration.h"
- #if __has_include("PayPalUtils.h")
- #import "PPOTDevice.h"
- #import "PPOTMacros.h"
- #else
- #import <PayPalUtils/PPOTDevice.h>
- #import <PayPalUtils/PPOTMacros.h>
- #endif
- #pragma mark - PPOTBillingAgreementRequest implementation
- @implementation PPOTBillingAgreementRequest
- #pragma mark - add subclass-specific info to appSwitchRequest
- - (PPOTSwitchRequest *)getAppSwitchRequestForConfigurationRecipe:(PPOTConfigurationRecipe *)configurationRecipe {
- PPOTCheckoutSwitchRequest *appSwitchRequest = nil;
- switch (configurationRecipe.target) {
- case PPOTRequestTargetOnDeviceApplication: {
- appSwitchRequest = [[PPOTCheckoutAppSwitchRequest alloc] initWithProtocolVersion:configurationRecipe.protocolVersion
- appGuid:[PPOTDevice appropriateIdentifier]
- clientID:self.clientID
- environment:self.environment
- callbackURLScheme:self.callbackURLScheme
- pairingId:self.pairingId];
- break;
- }
- case PPOTRequestTargetBrowser: {
- PPOTCheckoutBrowserSwitchRequest *browserSwitchRequest =
- [[PPOTCheckoutBrowserSwitchRequest alloc] initWithProtocolVersion:configurationRecipe.protocolVersion
- appGuid:[PPOTDevice appropriateIdentifier]
- clientID:self.clientID
- environment:self.environment
- callbackURLScheme:self.callbackURLScheme
- pairingId:self.pairingId];
- appSwitchRequest = browserSwitchRequest;
- break;
- }
- default: {
- break;
- }
- }
- if (appSwitchRequest) {
- appSwitchRequest.targetAppURLScheme = configurationRecipe.targetAppURLScheme;
- appSwitchRequest.responseType = PPAppSwitchResponseTypeWeb;
- appSwitchRequest.approvalURL = [self.approvalURL absoluteString];
- }
- return appSwitchRequest;
- }
- #pragma mark - configuration methods
- - (void)getAppropriateConfigurationRecipe:(void (^)(PPOTConfigurationRecipe *configurationRecipe))completionBlock {
- PPAssert(completionBlock, @"getAppropriateConfigurationRecipe: completionBlock is required");
- PPOTConfiguration *currentConfiguration = [PPOTConfiguration getCurrentConfiguration];
- PPOTConfigurationBillingAgreementRecipe *bestConfigurationRecipe = nil;
- for (PPOTConfigurationBillingAgreementRecipe *configurationRecipe in currentConfiguration.prioritizedBillingAgreementRecipes) {
- if (![self isConfigurationRecipeTargetSupported:configurationRecipe] ||
- ![self isConfigurationRecipeLocaleSupported:configurationRecipe]) {
- continue;
- }
- bestConfigurationRecipe = configurationRecipe;
- break;
- }
-
- completionBlock(bestConfigurationRecipe);
- }
- @end
|