Commit 6816f031 by Dima Bart

Update BUYOrder with properties returned by customer orders endpoint.

parent 8bff7c8e
...@@ -26,16 +26,135 @@ ...@@ -26,16 +26,135 @@
#import "BUYObject.h" #import "BUYObject.h"
@class BUYAddress;
@class BUYLineItem;
@class BUYShippingRate;
@class BUYLineItem;
@interface BUYOrder : BUYObject @interface BUYOrder : BUYObject
/** /**
* URL for the website showing the order status * Whether the order was cancelled or not.
*/ */
@property (nonatomic, strong, readonly) NSURL *statusURL; @property (nonatomic, assign, readonly) BOOL cancelled;
/**
* Whether the fulfillment was aborted or not.
*/
@property (nonatomic, assign, readonly) BOOL fulfillmentAborted;
/**
* The amount of discounts applied to the price of the order.
*/
@property (nonatomic, strong, readonly) NSDecimalNumber *discountSavings;
/**
* Price of the order before shipping and taxes
*/
@property (nonatomic, strong, readonly) NSDecimalNumber *subtotalPrice;
/**
* The sum of all the prices of all the items in the order, taxes and discounts included.
*/
@property (nonatomic, strong, readonly) NSDecimalNumber *totalPrice;
/** /**
* The customer's order name as represented by a number. * The customer's order name as represented by a number.
*/ */
@property (nonatomic, strong, readonly) NSString *name; @property (nonatomic, strong, readonly) NSString *name;
/**
* The reason why the order was cancelled. If the order was not cancelled, this value is "null." If the order was cancelled, the value will be one of the following:
*
* customer: The customer changed or cancelled the order.
* fraud: The order was fraudulent.
* inventory: Items in the order were not in inventory.
* other: The order was cancelled for a reason not in the list above.
*/
@property (nonatomic, strong, readonly) NSString *cancelReason;
/**
* The three letter code (ISO 4217) for the currency used for the payment.
*/
@property (nonatomic, strong, readonly) NSString *currency;
/**
* The state of finances. Value will be one of the following:
*
* pending: The finances are pending.
* authorized: The finances have been authorized.
* partially_paid: The finances have been partially paid.
* paid: The finances have been paid. (This is the default value.)
* partially_refunded: The finances have been partially refunded.
* refunded: The finances have been refunded.
* voided: The finances have been voided.
*/
@property (nonatomic, strong, readonly) NSString *financialStatus;
/**
* The status of the fulfillment. Value will be one of the following:
*
* nil: None of the line items in the order have been fulfilled.
* partial: At least one line item in the order has been fulfilled.
* fulfilled: Every line item in the order has been fulfilled.
*/
@property (nonatomic, strong, readonly) NSString *fulfillmentStatus;
/**
* A unique numeric identifier for the order. This one is used by the shop owner and customer.
* This is different from the id property, which is also a unique numeric identifier for the order,
* but used for API purposes.
*/
@property (nonatomic, strong, readonly) NSNumber *orderNumber;
/**
* The URL for the customer.
*/
@property (nonatomic, strong, readonly) NSURL *customerURL;
/**
* The URL pointing to the order status web page. The URL will be null unless the order was created from a checkout.
*/
@property (nonatomic, strong, readonly) NSURL *orderStatusURL;
/**
* URL for the website showing the order status
*/
@property (nonatomic, strong, readonly) NSURL *statusURL;
/**
* The date and time when the order was imported, in ISO 8601 format.
*/
@property (nonatomic, strong, readonly) NSDate *processedAt;
/**
* The date and time when the order was cancelled, in ISO 8601 format. Nil if the order was not cancelled.
*/
@property (nonatomic, strong, readonly) NSDate *cancelledAt;
/**
* The mailing address to where the order will be shipped. This address is optional and will not be available on orders that do not require one.
*/
@property (nonatomic, strong, readonly) BUYAddress *shippingAddress;
/**
* The mailing address associated with the payment method. This address is an optional field that will not be available on orders that do not require one.
*/
@property (nonatomic, strong, readonly) BUYAddress *billingAddress;
/**
* An array of shipping rate objects.
*/
@property (nonatomic, strong, readonly) NSArray<BUYShippingRate *> *shippingRates;
/**
* An array of fulfilled line item objects.
*/
@property (nonatomic, strong, readonly) NSArray<BUYLineItem *> *fulfilledLineItems;
/**
* An array of unfulfilled line item objects.
*/
@property (nonatomic, strong, readonly) NSArray<BUYLineItem *> *unfulfilledLineItems;
@end @end
...@@ -25,24 +25,48 @@ ...@@ -25,24 +25,48 @@
// //
#import "BUYOrder.h" #import "BUYOrder.h"
#import "BUYAddress.h"
#import "BUYLineItem.h"
#import "BUYShippingRate.h"
#import "NSURL+BUYAdditions.h" #import "NSURL+BUYAdditions.h"
#import "NSDictionary+BUYAdditions.h" #import "NSDictionary+BUYAdditions.h"
#import "NSDateFormatter+BUYAdditions.h"
@interface BUYOrder () #import "NSDecimalNumber+BUYAdditions.h"
@property (nonatomic, strong) NSURL *statusURL;
@property (nonatomic, strong) NSString *name;
@end
@implementation BUYOrder @implementation BUYOrder
- (void)updateWithDictionary:(NSDictionary *)dictionary - (void)updateWithDictionary:(NSDictionary *)dictionary
{ {
[super updateWithDictionary:dictionary]; [super updateWithDictionary:dictionary];
NSString *statusURLString = dictionary[@"status_url"];
self.statusURL = [NSURL buy_urlWithString:statusURLString]; NSDateFormatter *formatter = [NSDateFormatter dateFormatterForPublications];
self.name = [dictionary buy_objectForKey:@"name"];
_cancelled = [[dictionary buy_objectForKey:@"cancelled"] boolValue];
_fulfillmentAborted = [[dictionary buy_objectForKey:@"fulfillment_aborted"] boolValue];
_name = [dictionary buy_objectForKey:@"name"];
_cancelReason = [dictionary buy_objectForKey:@"cancel_reason"];
_currency = [dictionary buy_objectForKey:@"currency"];
_financialStatus = [dictionary buy_objectForKey:@"financial_status"];
_fulfillmentStatus = [dictionary buy_objectForKey:@"fulfillment_status"];
_orderNumber = [dictionary buy_objectForKey:@"order_number"];
_statusURL = [NSURL buy_urlWithString:dictionary[@"status_url"]];
_customerURL = [NSURL buy_urlWithString:dictionary[@"customer_url"]];
_orderStatusURL = [NSURL buy_urlWithString:dictionary[@"order_status_url"]];
_cancelledAt = [formatter dateFromString:[dictionary buy_objectForKey:@"cancelled_at"]];
_processedAt = [formatter dateFromString:[dictionary buy_objectForKey:@"processed_at"]];
_billingAddress = [BUYAddress convertObject:[dictionary buy_objectForKey:@"billing_address"]];
_shippingAddress = [BUYAddress convertObject:[dictionary buy_objectForKey:@"shipping_address"]];
_shippingRates = [BUYShippingRate convertJSONArray:[dictionary buy_objectForKey:@"shipping_methods"]];
_fulfilledLineItems = [BUYLineItem convertJSONArray:dictionary[@"fulfilled_line_items"]];
_unfulfilledLineItems = [BUYLineItem convertJSONArray:dictionary[@"unfulfilled_line_items"]];
_discountSavings = [NSDecimalNumber buy_decimalNumberFromJSON:[dictionary buy_objectForKey:@"discount_savings"]];
_subtotalPrice = [NSDecimalNumber buy_decimalNumberFromJSON:[dictionary buy_objectForKey:@"subtotal_price"]];
_totalPrice = [NSDecimalNumber buy_decimalNumberFromJSON:[dictionary buy_objectForKey:@"total_price"]];
} }
@end @end
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