Commit 67665b95 by Dima Bart

Rename to BUYPaymentToken protocol and associated classes.

parent cce5f56f
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
@class BUYOrder; @class BUYOrder;
@class BUYModelManager; @class BUYModelManager;
@protocol BUYPaymentSessionProvider; @protocol BUYPaymentToken;
/** /**
* The sort order for products in a collection * The sort order for products in a collection
...@@ -119,10 +119,10 @@ typedef NS_ENUM(NSUInteger, BUYStatus) { ...@@ -119,10 +119,10 @@ typedef NS_ENUM(NSUInteger, BUYStatus) {
* Return block containing a BUYCheckout, id<BUYPaymentSessionProvider> and/or an NSError * Return block containing a BUYCheckout, id<BUYPaymentSessionProvider> and/or an NSError
* *
* @param checkout The returned BUYCheckout * @param checkout The returned BUYCheckout
* @param sessionProvider An opaque session provider type that wraps necessary credentials for payment * @param paymentToken An opaque payment token type that wraps necessary credentials for payment
* @param error Optional NSError * @param error Optional NSError
*/ */
typedef void (^BUYDataCreditCardBlock)(BUYCheckout *checkout, id<BUYPaymentSessionProvider> sessionProvider, NSError *error); typedef void (^BUYDataCreditCardBlock)(BUYCheckout *checkout, id<BUYPaymentToken> paymentToken, NSError *error);
/** /**
* Return block containing a BUYCheckout and/or an NSError * Return block containing a BUYCheckout and/or an NSError
...@@ -454,11 +454,12 @@ typedef void (^BUYDataGiftCardBlock)(BUYGiftCard *giftCard, NSError *error); ...@@ -454,11 +454,12 @@ typedef void (^BUYDataGiftCardBlock)(BUYGiftCard *giftCard, NSError *error);
* We recommended using the BUYCheckout returned in the block. * We recommended using the BUYCheckout returned in the block.
* *
* @param checkout The BUYCheckout to complete * @param checkout The BUYCheckout to complete
* @param paymentToken Opaque payment token object
* @param block (^BUYDataCheckoutBlock)(BUYCheckout *checkout, NSError *error); * @param block (^BUYDataCheckoutBlock)(BUYCheckout *checkout, NSError *error);
* *
* @return The associated NSURLSessionDataTask * @return The associated NSURLSessionDataTask
*/ */
- (NSURLSessionDataTask*)completeCheckout:(BUYCheckout *)checkout sessionProvider:(id<BUYPaymentSessionProvider>)sessionProvider completion:(BUYDataCheckoutBlock)block; - (NSURLSessionDataTask*)completeCheckout:(BUYCheckout *)checkout paymentToken:(id<BUYPaymentToken>)paymentToken completion:(BUYDataCheckoutBlock)block;
/** /**
* Retrieve the status of a BUYCheckout. This checks the status of the current payment processing job for the provided checkout. * Retrieve the status of a BUYCheckout. This checks the status of the current payment processing job for the provided checkout.
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#import "BUYCart.h" #import "BUYCart.h"
#import "BUYCheckout.h" #import "BUYCheckout.h"
#import "BUYCreditCard.h" #import "BUYCreditCard.h"
#import "BUYCreditCardSessionProvider.h" #import "BUYCreditCardToken.h"
#import "BUYCollection.h" #import "BUYCollection.h"
#import "BUYError.h" #import "BUYError.h"
#import "BUYGiftCard.h" #import "BUYGiftCard.h"
...@@ -441,10 +441,9 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token ...@@ -441,10 +441,9 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return task; return task;
} }
- (NSURLSessionDataTask*)completeCheckout:(BUYCheckout *)checkout sessionProvider:(id<BUYPaymentSessionProvider>)sessionProvider completion:(BUYDataCheckoutBlock)block - (NSURLSessionDataTask*)completeCheckout:(BUYCheckout *)checkout paymentToken:(id<BUYPaymentToken>)paymentToken completion:(BUYDataCheckoutBlock)block
{ {
NSAssert(sessionProvider, @"Failed to complete checkout. BUYPaymentSessionProvider must not be nil."); NSAssert(checkout, @"Failed to complete checkout. Checkout must not be nil");
NSAssert(checkout, @"Failed to complete checkout. BUYCheckout must not be nil");
NSURLSessionDataTask *task = nil; NSURLSessionDataTask *task = nil;
...@@ -453,8 +452,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token ...@@ -453,8 +452,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
BOOL isFree = (checkout.paymentDue && checkout.paymentDue.floatValue == 0); BOOL isFree = (checkout.paymentDue && checkout.paymentDue.floatValue == 0);
NSData *data = nil; NSData *data = nil;
if ([sessionProvider hasPaymentSessionID]) { if (paymentToken) {
data = [NSJSONSerialization dataWithJSONObject:[sessionProvider jsonRepresentation] options:0 error:nil]; data = [NSJSONSerialization dataWithJSONObject:[paymentToken jsonRepresentation] options:0 error:nil];
} }
if (data || isFree) { if (data || isFree) {
...@@ -563,7 +562,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token ...@@ -563,7 +562,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
NSData *data = [NSJSONSerialization dataWithJSONObject:@{ @"checkout" : json } options:0 error:nil]; NSData *data = [NSJSONSerialization dataWithJSONObject:@{ @"checkout" : json } options:0 error:nil];
if (data) { if (data) {
return [self postPaymentRequestWithCheckout:checkout body:data completion:^(BUYCheckout *checkout, NSString *paymentSessionId, NSError *error) { return [self postPaymentRequestWithCheckout:checkout body:data completion:^(BUYCheckout *checkout, NSString *paymentSessionId, NSError *error) {
id<BUYPaymentSessionProvider> provider = [[BUYCreditCardSessionProvider alloc] initWithPaymentSessionID:paymentSessionId]; id<BUYPaymentToken> provider = [[BUYCreditCardToken alloc] initWithPaymentSessionID:paymentSessionId];
completion(checkout, provider, error); completion(checkout, provider, error);
}]; }];
......
// //
// BUYApplePaySessionProvider.h // BUYApplePayToken.h
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
@class PKPaymentToken; @class PKPaymentToken;
@interface BUYApplePaySessionProvider : NSObject <BUYPaymentSessionProvider> @interface BUYApplePayToken : NSObject <BUYPaymentToken>
@property (nonatomic, strong, readonly) PKPaymentToken *paymentToken; @property (nonatomic, strong, readonly) PKPaymentToken *paymentToken;
......
// //
// BUYApplePaySessionProvider.m // BUYApplePayToken.m
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#import <PassKit/PassKit.h> #import <PassKit/PassKit.h>
#endif #endif
#import "BUYApplePaySessionProvider.h" #import "BUYApplePayToken.h"
@implementation BUYApplePaySessionProvider @implementation BUYApplePayToken
#pragma mark - Init - #pragma mark - Init -
...@@ -49,11 +49,6 @@ ...@@ -49,11 +49,6 @@
#pragma mark - BUYPaymentSessionProvider - #pragma mark - BUYPaymentSessionProvider -
- (BOOL)hasPaymentSessionID
{
return self.paymentToken.paymentData.length > 0;
}
- (NSDictionary *)jsonRepresentation - (NSDictionary *)jsonRepresentation
{ {
return @{ return @{
......
// //
// BUYCreditCardSessionProvider.h // BUYCreditCardToken.h
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "BUYPaymentSessionProvider.h" #import "BUYPaymentSessionProvider.h"
@interface BUYCreditCardSessionProvider : NSObject <BUYPaymentSessionProvider> @interface BUYCreditCardToken : NSObject <BUYPaymentToken>
@property (nonatomic, strong, readonly) NSString *paymentSessionID; @property (nonatomic, strong, readonly) NSString *paymentSessionID;
......
// //
// BUYCreditCardSessionProvider.m // BUYCreditCardToken.m
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
// THE SOFTWARE. // THE SOFTWARE.
// //
#import "BUYCreditCardSessionProvider.h" #import "BUYCreditCardToken.h"
@implementation BUYCreditCardSessionProvider @implementation BUYCreditCardToken
#pragma mark - Init - #pragma mark - Init -
...@@ -41,11 +41,6 @@ ...@@ -41,11 +41,6 @@
#pragma mark - BUYPaymentSessionProvider - #pragma mark - BUYPaymentSessionProvider -
- (BOOL)hasPaymentSessionID
{
return self.paymentSessionID.length > 0;
}
- (NSDictionary *)jsonRepresentation - (NSDictionary *)jsonRepresentation
{ {
return @{ return @{
......
// //
// BUYPaymentSessionProvider.h // BUYPaymentToken.h
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -24,9 +24,8 @@ ...@@ -24,9 +24,8 @@
// THE SOFTWARE. // THE SOFTWARE.
// //
@protocol BUYPaymentSessionProvider <NSObject> @protocol BUYPaymentToken <NSObject>
- (BOOL)hasPaymentSessionID;
- (NSDictionary *)jsonRepresentation; - (NSDictionary *)jsonRepresentation;
@end @end
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#import "BUYModelManager.h" #import "BUYModelManager.h"
#import "BUYShop.h" #import "BUYShop.h"
#import "BUYShopifyErrorCodes.h" #import "BUYShopifyErrorCodes.h"
#import "BUYApplePaySessionProvider.h" #import "BUYApplePayToken.h"
const NSTimeInterval PollDelay = 0.5; const NSTimeInterval PollDelay = 0.5;
...@@ -114,10 +114,10 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -114,10 +114,10 @@ const NSTimeInterval PollDelay = 0.5;
if (checkout && error == nil) { if (checkout && error == nil) {
self.checkout = checkout; self.checkout = checkout;
id<BUYPaymentSessionProvider> provider = [[BUYApplePaySessionProvider alloc] initWithPaymentToken:payment.token]; id<BUYPaymentToken> token = [[BUYApplePayToken alloc] initWithPaymentToken:payment.token];
//Now that the checkout is up to date, call complete. //Now that the checkout is up to date, call complete.
[self.client completeCheckout:checkout sessionProvider:provider completion:^(BUYCheckout *checkout, NSError *error) { [self.client completeCheckout:checkout paymentToken:token completion:^(BUYCheckout *checkout, NSError *error) {
if (checkout && error == nil) { if (checkout && error == nil) {
self.checkout = checkout; self.checkout = checkout;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment