ZalandoCommerceAPI
public struct ZalandoCommerceAPI
Provides all functional API calls with their business logic. Main entry point for the ZalandoCommerceAPI framework.
Note
If not specified otherwise – all API calls require user to be logged in and accepted a consent. OtherwiseResult.failure with
APIError.unauthorized is returned.
-
Configuration of a client handling API calls
Declaration
Swift
public let config: Config
-
Fetches
Articlewith given SKU.Declaration
Swift
public func article(with sku: ConfigSKU, completion: @escaping APIResultCompletion<Article>)Parameters
skuSKU of an article to fetch
completioncompletes async with
APIResult.successwithArticle -
Fetches current logged user as
Customer.Declaration
Swift
public func customer(completion: @escaping APIResultCompletion<Customer>)Parameters
completioncompletes async with
APIResult.successwith logged user asCustomer -
Creates
Cartwith givenCartItemRequestitems.Declaration
Swift
public func createCart(with cartItemRequests: [CartItemRequest], completion: @escaping APIResultCompletion<Cart>)Parameters
cartItemRequestslist articles SKUs with quantities to be added to cart
completioncompletes async with
APIResult.successwithCartmodel created. -
Creates
Cart, and makesCheckoutfrom it. Additionally handle specific corner cases.Handled cases: - when article has no stock available
completionreturnsResult.failurewithCheckoutError.outOfStock- when checkout creation failscompletionreturnsResult.failurewithAPIError.checkoutFailedand createdCartDeclaration
Swift
public func createCartCheckout(with cartItemRequest: CartItemRequest, addresses: CheckoutAddresses? = nil, completion: @escaping APIResultCompletion<CartCheckout>)Parameters
cartItemRequestarticle SKU and quantity to be added to the cart
addressesaddresses to be passed to the checkout
completioncompletes async with
APIResult.successwithCartCheckout. -
Creates
Checkoutbased onCartId.Declaration
Swift
public func createCheckout(from cartId: CartId, addresses: CheckoutAddresses? = nil, completion: @escaping APIResultCompletion<Checkout>)Parameters
cartIdidentifier of a cart (
Cart.id)addressesset of billing and shipping addresses
completioncompletes async with
APIResult.successwithCheckout. -
Updates
Checkoutshipping and/or billing addresses.Declaration
Swift
public func updateCheckout(with checkoutId: CheckoutId, updateCheckoutRequest: UpdateCheckoutRequest, completion: @escaping APIResultCompletion<Checkout>)Parameters
checkoutIdidentifier of a checkout (
Checkout.id)updateCheckoutRequestnew shipping and/or billing address
completioncompletes async with
APIResult.successwithCheckout. -
Places order based on formerly created checkout.
Declaration
Swift
public func createOrder(from checkout: Checkout, completion: @escaping APIResultCompletion<Order>)Parameters
checkoutIdidentifier of a checkout (
Checkout.id)completioncompletes async with
APIResult.successwithOrder. -
Retrieves details of
GuestCheckout.Declaration
Swift
public func guestCheckout(with guestCheckoutId: GuestCheckoutId, completion: @escaping APIResultCompletion<GuestCheckout>)Parameters
checkoutIdidentifier of a guest checkout (
GuestCheckout.id)completioncompletes async with
APIResult.successwithGuestCheckout. -
Retrieves
URLcontaining web page handling payment process.Note
The result
URLshould be passed to a web view, and the response returned should be parsed usingPaymentStatus.Declaration
Swift
public func guestCheckoutPaymentSelectionURL(request: GuestPaymentSelectionRequest, completion: @escaping APIResultCompletion<URL>)Parameters
requestrequest containing all the data needed by Guest Checkout
completioncompletes async with
APIResult.successwithURL. -
Creates order from a checkout in Guest Checkout mode.
Declaration
Swift
public func createGuestOrder(request: GuestOrderRequest, completion: @escaping APIResultCompletion<GuestOrder>)Parameters
requestguest checkout with token
completioncompletes async with
APIResult.successwithGuestOrder. -
Fetches list of
UserAddresscontaining all customer’s addresses available for both shipping and billing.Declaration
Swift
public func addresses(completion: @escaping APIResultCompletion<[UserAddress]>)Parameters
completioncompletes async with
APIResult.successwith[UserAddress] -
Creates new address in customer’s address book.
Declaration
Swift
public func createAddress(with request: CreateAddressRequest, completion: @escaping APIResultCompletion<UserAddress>)Parameters
requestaddress details request
completioncompletes async with
APIResult.successwith createdUserAddress. -
Updates customer’s address.
Declaration
Swift
public func updateAddress(with request: UpdateAddressRequest, completion: @escaping APIResultCompletion<UserAddress>)Parameters
requestaddress details to be updated
completioncompletes async with
APIResult.successwith updatedUserAddress. -
Deletes given
EquatableAddressfrom customer’s address book.Declaration
Swift
public func delete(_ address: EquatableAddress, completion: @escaping APIResultCompletion<Bool>)Parameters
addressEquatableAddressto be removed.completioncompletes async with
APIResult.successwith success status. -
Verifies correctness of a given address
Declaration
Swift
public func checkAddress(with request: CheckAddressRequest, completion: @escaping APIResultCompletion<CheckAddressResponse>)Parameters
requestaddress data
completioncompletes async with
APIResult.successwithCheckAddressResponse -
Fetches recommendations for given article’s SKU
Declaration
Swift
public func recommendations(for sku: ConfigSKU, with recommendationConfig: RecommendationConfig, completion: @escaping APIResultCompletion<[Recommendation]>)Parameters
skuarticle’s identifier to on which recommendations are based (
Article.sku)recommendationConfigRecommendationConfigcompletioncompletes async with
APIResult.successwith[Recommendation]
-
Configures and returns API client based on given options.
When neither
Optionsare passed or correct, nor$INFOPLIST_FILEcontains required keys and values –completionretunsResult.failurewith error returned fromOptions.validate()Note
See configuration and project structure
Declaration
Swift
public static func configure(options: Options? = nil, completion: @escaping ResultCompletion<ZalandoCommerceAPI>)Parameters
optionsOptions for API client to be created. When
nil,$INFOPLIST_FILEfile of the app is used as configuration.completionFired when network configuration call is finished. Contains
Result.successwithZalandoCommerceAPIorResult.failurewithErrorreason.
-
Determines if a client has an access token to call restricted endpoints. Having token doesn’t guarantee it’s unexpired or invalidated.
Declaration
Swift
public var isAuthorized: Bool -
Authorizes a client with given access token required in restricted endpoints.
Note
Stores
tokensecurely and makes it globally available for all calls to restricted endpoints identified by sameOptions.environmentPostcondition
Postcondition:
- If a client is authorized successfully
NSNotification.Name.ZalandoCommerceAPIAuthorizedNSNotification.Name.ZalandoCommerceAPIAuthorizationChangedare posted onNotificationCenter.default - Both notifications contain
ZalandoCommerceAPIinstance as sendingobject, anduserInfocontainingZALANDO_COMMERCE_CLIENT_IDequal toOptions.clientId, andZALANDO_COMMERCE_USE_SANDBOXequal toOptions.useSandboxEnvironment.
Declaration
Swift
public func authorize(with token: AuthorizationToken) -> BoolParameters
tokenaccess token passed to all restricted endpoint calls
Return Value
trueif token was correctly stored and client is authorized, otherwisefalse - If a client is authorized successfully
-
Deauthorizes a client from accessing restricted endpoints.
Postcondition
- If a client is deauthorized successfully
NSNotification.Name.ZalandoCommerceAPIDeauthorizedandNSNotification.Name.ZalandoCommerceAPIAuthorizationChangedare posted onNotificationCenter.default. - Both notifications contain
ZalandoCommerceAPIinstance as sendingobject, anduserInfocontainingZALANDO_COMMERCE_CLIENT_IDequal toOptions.clientId, andZALANDO_COMMERCE_USE_SANDBOXequal toOptions.useSandboxEnvironment.
Declaration
Swift
public func deauthorize() - If a client is deauthorized successfully
-
Deauthorizes all clients by removing all stored tokens and notifying about it - SeeAlso:
ZalandoCommerceAPI.deauthorize(with:)Declaration
Swift
public static func deauthorizeAll()
View on GitHub
ZalandoCommerceAPI Struct Reference