Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
be59c98e
Commit
be59c98e
authored
May 20, 2016
by
Gabriel O'Flaherty-Chan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #169 from Shopify/task/payment-provider-refactor
Refactor payment provider
parents
a8ae05e0
19316426
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
43 deletions
+58
-43
BUYPaymentProviderTests.m
...le Buy SDK/Mobile Buy SDK Tests/BUYPaymentProviderTests.m
+1
-1
BUYApplePayPaymentProvider.m
...le Buy SDK/Payment Providers/BUYApplePayPaymentProvider.m
+16
-16
BUYPaymentProvider.h
...SDK/Mobile Buy SDK/Payment Providers/BUYPaymentProvider.h
+2
-10
BUYWebCheckoutPaymentProvider.m
...Buy SDK/Payment Providers/BUYWebCheckoutPaymentProvider.m
+2
-2
BUYError+BUYAdditions.m
Mobile Buy SDK/Mobile Buy SDK/Utils/BUYError+BUYAdditions.m
+37
-14
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYPaymentProviderTests.m
View file @
be59c98e
...
@@ -240,7 +240,7 @@
...
@@ -240,7 +240,7 @@
{
{
}
}
-
(
void
)
paymentProvider
:
(
id
<
BUYPaymentProvider
>
)
provider
didFail
Checkout
WithError
:
(
NSError
*
)
error
;
-
(
void
)
paymentProvider
:
(
id
<
BUYPaymentProvider
>
)
provider
didFailWithError
:
(
NSError
*
)
error
;
{
{
if
(
self
.
expectations
[
@"failedCheckout"
])
{
if
(
self
.
expectations
[
@"failedCheckout"
])
{
[
self
.
expectations
[
@"failedCheckout"
]
fulfill
];
[
self
.
expectations
[
@"failedCheckout"
]
fulfill
];
...
...
Mobile Buy SDK/Mobile Buy SDK/Payment Providers/BUYApplePayPaymentProvider.m
View file @
be59c98e
...
@@ -100,8 +100,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -100,8 +100,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
[
self
.
client
getShop
:
^
(
BUYShop
*
theShop
,
NSError
*
error
)
{
[
self
.
client
getShop
:
^
(
BUYShop
*
theShop
,
NSError
*
error
)
{
if
(
error
)
{
if
(
error
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
Checkout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
Checkout
WithError
:
error
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
error
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
}
}
...
@@ -115,8 +115,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -115,8 +115,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
dispatch_group_enter
(
group
);
dispatch_group_enter
(
group
);
[
self
.
client
handleCheckout
:
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
.
client
handleCheckout
:
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
error
)
{
if
(
error
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
Checkout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
Checkout
WithError
:
error
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
error
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
}
}
...
@@ -181,8 +181,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -181,8 +181,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
[
self
.
delegate
paymentProvider
:
self
wantsControllerPresented
:
controller
];
[
self
.
delegate
paymentProvider
:
self
wantsControllerPresented
:
controller
];
}
}
else
{
else
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
Checkout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
Checkout
WithError
:
nil
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
nil
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
}
}
...
@@ -225,15 +225,15 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -225,15 +225,15 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
self
.
paymentAuthorizationStatus
=
status
;
self
.
paymentAuthorizationStatus
=
status
;
switch
(
status
)
{
switch
(
status
)
{
case
PKPaymentAuthorizationStatusFailure
:
case
PKPaymentAuthorizationStatusFailure
:
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
Checkout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
Checkout
WithError
:
self
.
applePayHelper
.
lastError
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
self
.
applePayHelper
.
lastError
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
break
;
break
;
case
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
:
case
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
:
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
ToUpdateCheckout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
ToUpdateCheckout
WithError
:
self
.
applePayHelper
.
lastError
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
self
.
applePayHelper
.
lastError
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
break
;
break
;
...
@@ -263,8 +263,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -263,8 +263,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
{
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingMethod
:
shippingMethod
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingMethod
:
shippingMethod
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
ToUpdateCheckout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
ToUpdateCheckout
WithError
:
self
.
applePayHelper
.
lastError
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
self
.
applePayHelper
.
lastError
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
}
}
...
@@ -276,8 +276,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -276,8 +276,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
{
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingAddress
:
address
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKShippingMethod
*>
*
_Nonnull
shippingMethods
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingAddress
:
address
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKShippingMethod
*>
*
_Nonnull
shippingMethods
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
ToUpdateCheckout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
ToUpdateCheckout
WithError
:
self
.
applePayHelper
.
lastError
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
self
.
applePayHelper
.
lastError
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
}
}
...
@@ -289,8 +289,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
...
@@ -289,8 +289,8 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
{
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingContact
:
contact
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKShippingMethod
*>
*
_Nonnull
shippingMethods
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
[
self
.
applePayHelper
paymentAuthorizationViewController
:
controller
didSelectShippingContact
:
contact
completion
:^
(
PKPaymentAuthorizationStatus
status
,
NSArray
<
PKShippingMethod
*>
*
_Nonnull
shippingMethods
,
NSArray
<
PKPaymentSummaryItem
*>
*
_Nonnull
summaryItems
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
(
status
==
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
ToUpdateCheckout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
ToUpdateCheckout
WithError
:
self
.
applePayHelper
.
lastError
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
self
.
applePayHelper
.
lastError
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey
object
:
self
];
}
}
...
...
Mobile Buy SDK/Mobile Buy SDK/Payment Providers/BUYPaymentProvider.h
View file @
be59c98e
...
@@ -75,20 +75,12 @@ extern NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey;
...
@@ -75,20 +75,12 @@ extern NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey;
-
(
void
)
paymentProviderDidDismissCheckout
:(
id
<
BUYPaymentProvider
>
)
provider
;
-
(
void
)
paymentProviderDidDismissCheckout
:(
id
<
BUYPaymentProvider
>
)
provider
;
/**
/**
* Called when a checkout
failed to update
* Called when a checkout
payment operation has failed
*
*
* @param provider the `BUYPaymentProvider`
* @param provider the `BUYPaymentProvider`
* @param error the optional `NSError`
* @param error the optional `NSError`
*/
*/
-
(
void
)
paymentProvider
:(
id
<
BUYPaymentProvider
>
)
provider
didFailToUpdateCheckoutWithError
:(
NSError
*
)
error
;
-
(
void
)
paymentProvider
:(
id
<
BUYPaymentProvider
>
)
provider
didFailWithError
:(
nullable
NSError
*
)
error
;
/**
* Called when the checkout failed
*
* @param provider the `BUYPaymentProvider`
* @param error the optional `NSError`
*/
-
(
void
)
paymentProvider
:(
id
<
BUYPaymentProvider
>
)
provider
didFailCheckoutWithError
:(
NSError
*
_Nullable
)
error
;
/**
/**
* Called when the checkout has completed
* Called when the checkout has completed
...
...
Mobile Buy SDK/Mobile Buy SDK/Payment Providers/BUYWebCheckoutPaymentProvider.m
View file @
be59c98e
...
@@ -128,8 +128,8 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
...
@@ -128,8 +128,8 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
[
self
openWebCheckout
:
checkout
];
[
self
openWebCheckout
:
checkout
];
}
}
else
{
else
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFail
Checkout
WithError
:
)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
paymentProvider
:
didFailWithError
:
)])
{
[
self
.
delegate
paymentProvider
:
self
didFail
Checkout
WithError
:
error
];
[
self
.
delegate
paymentProvider
:
self
didFailWithError
:
error
];
}
}
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
BUYPaymentProviderDidFailCheckoutNotificationKey
object
:
self
];
...
...
Mobile Buy SDK/Mobile Buy SDK/Utils/BUYError+BUYAdditions.m
View file @
be59c98e
...
@@ -25,26 +25,49 @@
...
@@ -25,26 +25,49 @@
//
//
#import "BUYError+BUYAdditions.h"
#import "BUYError+BUYAdditions.h"
#import "NSArray+BUYAdditions.h"
@interface
NSDictionary
(
BUYCheckoutErrorParsing
)
-
(
NSDictionary
*
)
buy_errorsDictionary
;
-
(
NSDictionary
*
)
buy_checkoutErrorsDictionary
;
-
(
NSArray
*
)
buy_lineItemErrors
;
@end
@implementation
NSDictionary
(
BUYCheckoutErrorParsing
)
-
(
NSDictionary
*
)
buy_errorsDictionary
{
NSDictionary
*
errorsDictionary
=
self
[
@"errors"
];
return
[
errorsDictionary
isKindOfClass
:[
NSDictionary
class
]]
?
errorsDictionary
:
nil
;
}
-
(
NSDictionary
*
)
buy_checkoutErrorsDictionary
{
NSDictionary
*
checkoutErrorsDictionary
=
[
self
buy_errorsDictionary
][
@"checkout"
];
return
[
checkoutErrorsDictionary
isKindOfClass
:[
NSDictionary
class
]]
?
checkoutErrorsDictionary
:
nil
;
}
-
(
NSArray
*
)
buy_lineItemErrors
{
NSArray
*
lineItemErrors
=
[
self
buy_checkoutErrorsDictionary
][
@"line_items"
];
return
[
lineItemErrors
isKindOfClass
:[
NSArray
class
]]
?
lineItemErrors
:
nil
;
}
@end
@implementation
BUYError
(
Checkout
)
@implementation
BUYError
(
Checkout
)
+
(
NSArray
<
BUYError
*>
*
)
errorsFromCheckoutJSON
:(
NSDictionary
*
)
json
+
(
NSArray
<
BUYError
*>
*
)
errorsFromCheckoutJSON
:(
NSDictionary
*
)
json
{
{
NSArray
*
lineItems
=
json
[
@"errors"
][
@"checkout"
][
@"line_items"
];
return
[[
json
buy_lineItemErrors
]
buy_map
:
^
id
(
NSDictionary
<
NSString
*
,
NSArray
*>
*
lineItemError
)
{
NSMutableArray
*
errors
=
[
NSMutableArray
array
];
return
[
lineItemError
isKindOfClass
:[
NSDictionary
class
]]
?
[
self
errorWithJSONDictionary
:
lineItemError
]
:
[
NSNull
null
];
}];
}
for
(
NSDictionary
<
NSString
*
,
NSArray
*>
*
lineItem
in
lineItems
)
{
+
(
BUYError
*
)
errorWithJSONDictionary
:(
NSDictionary
<
NSString
*
,
NSArray
*>
*
)
dictionary
if
(
lineItem
==
(
id
)[
NSNull
null
])
{
{
[
errors
addObject
:
lineItem
];
NSString
*
key
=
dictionary
.
allKeys
.
firstObject
;
}
return
[[
self
alloc
]
initWithKey
:
key
json
:
dictionary
[
key
].
firstObject
];
else
{
for
(
NSString
*
key
in
lineItem
.
allKeys
)
{
NSDictionary
*
reason
=
[
lineItem
[
key
]
firstObject
];
[
errors
addObject
:[[
BUYError
alloc
]
initWithKey
:
key
json
:
reason
]];
};
}
};
return
errors
;
}
}
-
(
NSString
*
)
quantityRemainingMessage
-
(
NSString
*
)
quantityRemainingMessage
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment