Commit 67665b95 by Dima Bart

Rename to BUYPaymentToken protocol and associated classes.

parent cce5f56f
......@@ -40,7 +40,7 @@
@class BUYOrder;
@class BUYModelManager;
@protocol BUYPaymentSessionProvider;
@protocol BUYPaymentToken;
/**
* The sort order for products in a collection
......@@ -118,11 +118,11 @@ typedef NS_ENUM(NSUInteger, BUYStatus) {
/**
* Return block containing a BUYCheckout, id<BUYPaymentSessionProvider> and/or an NSError
*
* @param checkout The returned BUYCheckout
* @param sessionProvider An opaque session provider type that wraps necessary credentials for payment
* @param error Optional NSError
* @param checkout The returned BUYCheckout
* @param paymentToken An opaque payment token type that wraps necessary credentials for payment
* @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
......@@ -453,12 +453,13 @@ typedef void (^BUYDataGiftCardBlock)(BUYGiftCard *giftCard, NSError *error);
* Note: There's no guarantee that the BUYCheckout returned will be the same as the one that is passed in.
* We recommended using the BUYCheckout returned in the block.
*
* @param checkout The BUYCheckout to complete
* @param block (^BUYDataCheckoutBlock)(BUYCheckout *checkout, NSError *error);
* @param checkout The BUYCheckout to complete
* @param paymentToken Opaque payment token object
* @param block (^BUYDataCheckoutBlock)(BUYCheckout *checkout, NSError *error);
*
* @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.
......
......@@ -30,7 +30,7 @@
#import "BUYCart.h"
#import "BUYCheckout.h"
#import "BUYCreditCard.h"
#import "BUYCreditCardSessionProvider.h"
#import "BUYCreditCardToken.h"
#import "BUYCollection.h"
#import "BUYError.h"
#import "BUYGiftCard.h"
......@@ -441,10 +441,9 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
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. BUYCheckout must not be nil");
NSAssert(checkout, @"Failed to complete checkout. Checkout must not be nil");
NSURLSessionDataTask *task = nil;
......@@ -453,8 +452,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
BOOL isFree = (checkout.paymentDue && checkout.paymentDue.floatValue == 0);
NSData *data = nil;
if ([sessionProvider hasPaymentSessionID]) {
data = [NSJSONSerialization dataWithJSONObject:[sessionProvider jsonRepresentation] options:0 error:nil];
if (paymentToken) {
data = [NSJSONSerialization dataWithJSONObject:[paymentToken jsonRepresentation] options:0 error:nil];
}
if (data || isFree) {
......@@ -563,7 +562,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
NSData *data = [NSJSONSerialization dataWithJSONObject:@{ @"checkout" : json } options:0 error:nil];
if (data) {
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);
}];
......
//
// BUYApplePaySessionProvider.h
// BUYApplePayToken.h
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -29,7 +29,7 @@
@class PKPaymentToken;
@interface BUYApplePaySessionProvider : NSObject <BUYPaymentSessionProvider>
@interface BUYApplePayToken : NSObject <BUYPaymentToken>
@property (nonatomic, strong, readonly) PKPaymentToken *paymentToken;
......
//
// BUYApplePaySessionProvider.m
// BUYApplePayToken.m
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -28,9 +28,9 @@
#import <PassKit/PassKit.h>
#endif
#import "BUYApplePaySessionProvider.h"
#import "BUYApplePayToken.h"
@implementation BUYApplePaySessionProvider
@implementation BUYApplePayToken
#pragma mark - Init -
......@@ -49,11 +49,6 @@
#pragma mark - BUYPaymentSessionProvider -
- (BOOL)hasPaymentSessionID
{
return self.paymentToken.paymentData.length > 0;
}
- (NSDictionary *)jsonRepresentation
{
return @{
......
//
// BUYCreditCardSessionProvider.h
// BUYCreditCardToken.h
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -27,7 +27,7 @@
#import <Foundation/Foundation.h>
#import "BUYPaymentSessionProvider.h"
@interface BUYCreditCardSessionProvider : NSObject <BUYPaymentSessionProvider>
@interface BUYCreditCardToken : NSObject <BUYPaymentToken>
@property (nonatomic, strong, readonly) NSString *paymentSessionID;
......
//
// BUYCreditCardSessionProvider.m
// BUYCreditCardToken.m
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -24,9 +24,9 @@
// THE SOFTWARE.
//
#import "BUYCreditCardSessionProvider.h"
#import "BUYCreditCardToken.h"
@implementation BUYCreditCardSessionProvider
@implementation BUYCreditCardToken
#pragma mark - Init -
......@@ -41,11 +41,6 @@
#pragma mark - BUYPaymentSessionProvider -
- (BOOL)hasPaymentSessionID
{
return self.paymentSessionID.length > 0;
}
- (NSDictionary *)jsonRepresentation
{
return @{
......
//
// BUYPaymentSessionProvider.h
// BUYPaymentToken.h
// Mobile Buy SDK
//
// Created by Shopify.
......@@ -24,9 +24,8 @@
// THE SOFTWARE.
//
@protocol BUYPaymentSessionProvider <NSObject>
@protocol BUYPaymentToken <NSObject>
- (BOOL)hasPaymentSessionID;
- (NSDictionary *)jsonRepresentation;
@end
......@@ -33,7 +33,7 @@
#import "BUYModelManager.h"
#import "BUYShop.h"
#import "BUYShopifyErrorCodes.h"
#import "BUYApplePaySessionProvider.h"
#import "BUYApplePayToken.h"
const NSTimeInterval PollDelay = 0.5;
......@@ -114,10 +114,10 @@ const NSTimeInterval PollDelay = 0.5;
if (checkout && error == nil) {
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.
[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) {
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