forked from stripe/stripe-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShippingManager.m
More file actions
50 lines (43 loc) · 1.71 KB
/
ShippingManager.m
File metadata and controls
50 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// ShippingManager.m
// StripeExample
//
// Created by Jack Flintermann on 10/22/14.
// Copyright (c) 2014 Stripe. All rights reserved.
//
#import "ShippingManager.h"
#import <PassKit/PassKit.h>
@implementation ShippingManager
- (NSArray *)defaultShippingMethods {
return [self californiaShippingMethods];
}
- (void)fetchShippingCostsForAddress:(CNPostalAddress *)address completion:(void (^)(NSArray *shippingMethods, NSError *error))completion {
// you could, for example, go to UPS here and calculate shipping costs to that address.
if ([address.state isEqualToString:@"CA"]) {
completion([self californiaShippingMethods], nil);
} else {
completion([self internationalShippingMethods], nil);
}
}
- (NSArray *)californiaShippingMethods {
PKShippingMethod *upsGround = [[PKShippingMethod alloc] init];
upsGround.amount = [NSDecimalNumber decimalNumberWithString:@"0.00"];
upsGround.label = @"UPS Ground";
upsGround.detail = @"Arrives in 3-5 days";
upsGround.identifier = @"ups_ground";
PKShippingMethod *fedex = [[PKShippingMethod alloc] init];
fedex.amount = [NSDecimalNumber decimalNumberWithString:@"5.99"];
fedex.label = @"FedEx";
fedex.detail = @"Arrives tomorrow";
fedex.identifier = @"fedex";
return @[upsGround, fedex];
}
- (NSArray *)internationalShippingMethods {
PKShippingMethod *upsWorldwide = [[PKShippingMethod alloc] init];
upsWorldwide.amount = [NSDecimalNumber decimalNumberWithString:@"10.99"];
upsWorldwide.label = @"UPS Worldwide Express";
upsWorldwide.detail = @"Arrives in 1-3 days";
upsWorldwide.identifier = @"ups_worldwide";
return [[self californiaShippingMethods] arrayByAddingObject:upsWorldwide];;
}
@end