add status to shipping validation block
This commit is contained in:
parent
3bb753e0a9
commit
cdcf6913eb
|
@ -245,7 +245,7 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate, STPSh
|
|||
shippingMethod2.detail = "Arrives tomorrow"
|
||||
shippingMethod2.identifier = "456"
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
completion(nil, [shippingMethod1, shippingMethod2])
|
||||
completion(.valid, nil, [shippingMethod1, shippingMethod2], shippingMethod2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,20 @@ typedef NS_ENUM(NSUInteger, STPShippingType) {
|
|||
STPShippingTypeDelivery,
|
||||
};
|
||||
|
||||
/**
|
||||
* An enum representing the status of a shipping address validation.
|
||||
*/
|
||||
typedef NS_ENUM(NSUInteger, STPShippingStatus) {
|
||||
/**
|
||||
* The shipping address is valid.
|
||||
*/
|
||||
STPShippingStatusValid,
|
||||
/**
|
||||
* The shipping address is invalid.
|
||||
*/
|
||||
STPShippingStatusInvalid,
|
||||
};
|
||||
|
||||
/**
|
||||
* An enum representing the status of a payment requested from the user.
|
||||
*/
|
||||
|
@ -68,7 +82,9 @@ typedef void (^STPTokenCompletionBlock)(STPToken * __nullable token, NSError * _
|
|||
* A callback to be run with a validation result and shipping methods for a
|
||||
* shipping address.
|
||||
*
|
||||
* @param shippingValidationError If the shipping address is invalid, an error describing the issue with the address. Will be nil if the address is valid.
|
||||
* @param shippingStatus An enum representing whether the shipping address is valid.
|
||||
* @param shippingValidationError If the shipping address is invalid, an error describing the issue with the address. If no error is given and the address is invalid, the default error message will be used.
|
||||
* @param shippingMethods The shipping methods available for the address.
|
||||
* @param selectedShippingMethod The default selected shipping method for the address.
|
||||
*/
|
||||
typedef void (^STPShippingMethodsCompletionBlock)(NSError * __nullable shippingValidationError, NSArray<PKShippingMethod *>* __nonnull shippingMethods);
|
||||
typedef void (^STPShippingMethodsCompletionBlock)(STPShippingStatus status, NSError * __nullable shippingValidationError, NSArray<PKShippingMethod *>* __nullable shippingMethods, PKShippingMethod * __nullable selectedShippingMethod);
|
||||
|
|
|
@ -211,12 +211,12 @@
|
|||
switch (self.configuration.shippingType) {
|
||||
case STPShippingTypeShipping: {
|
||||
self.loading = YES;
|
||||
[self.delegate shippingAddressViewController:self didEnterAddress:address completion:^(NSError *shippingValidationError, NSArray<PKShippingMethod *> * _Nonnull shippingMethods) {
|
||||
[self.delegate shippingAddressViewController:self didEnterAddress:address completion:^(STPShippingStatus status, NSError * __nullable shippingValidationError, NSArray<PKShippingMethod *>* __nullable shippingMethods, PKShippingMethod * __nullable selectedShippingMethod) {
|
||||
self.loading = NO;
|
||||
if (shippingValidationError == nil) {
|
||||
if (status == STPShippingStatusValid) {
|
||||
if ([shippingMethods count] > 0) {
|
||||
STPShippingMethodsViewController *nextViewController = [[STPShippingMethodsViewController alloc] initWithShippingMethods:shippingMethods
|
||||
selectedShippingMethod:self.selectedShippingMethod
|
||||
selectedShippingMethod:selectedShippingMethod
|
||||
currency:self.currency
|
||||
theme:self.theme];
|
||||
nextViewController.delegate = self;
|
||||
|
@ -248,8 +248,14 @@
|
|||
|
||||
- (void)handleShippingValidationError:(NSError *)error {
|
||||
[[self firstEmptyField] becomeFirstResponder];
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:error.localizedDescription
|
||||
message:error.localizedFailureReason
|
||||
NSString *title = STPLocalizedString(@"Invalid Shipping Address", @"Shipping form error message");
|
||||
NSString *message = nil;
|
||||
if (error != nil) {
|
||||
title = error.localizedDescription;
|
||||
message = error.localizedFailureReason;
|
||||
}
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
|
||||
message:message
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:STPLocalizedString(@"OK", @"ok button")
|
||||
style:UIAlertActionStyleCancel
|
||||
|
|
Loading…
Reference in New Issue