Commit add3e35d by Brent Gulanowski

Merge branch 'integration/sdk-2.0' into task/payment-providers

parents 404803d8 395d8b2f
# Mobile Buy SDK Customer Sample App
The Customer Sample App demonstrates how to perform several tasks using the customer API.
- Login customer
- Create customer account
- Fetch customer orders
### Configuration
First, configure the application with your shop domain, API key and app ID.
```swift
let shopDomain: String = ""
let apiKey: String = ""
let appID: String = ""
```
### Overview
The Customer Sample App demonstates the usage of the customer API that lets you create a customer account, login with a customer account and show customer's orders after authentication.
{ {
"application_name": "MobileBuyTest", "application_name": "MobileBuyTest",
<<<<<<< Updated upstream
"shop_domain": "", "shop_domain": "",
"api_key": "", "api_key": "",
"channel_id": "", "channel_id": "",
...@@ -8,64 +7,51 @@ ...@@ -8,64 +7,51 @@
"merchant_id": "", "merchant_id": "",
"customer_email": "", "customer_email": "",
"customer_password": "", "customer_password": "",
=======
"shop_domain": "mobilebuysdktestshop.myshopify.com",
"api_key": "fccaa7eceb7d210a6e5366e676d4edff",
"channel_id": "26915715",
"app_id": "8",
"merchant_id": "merchant.com.shopify.applepay",
>>>>>>> Stashed changes
"product_ids": [ "product_ids": [
"2096060931", "",
"2096063363", ""
"2096062275",
"2096057987"
], ],
<<<<<<< Updated upstream
"variants": { "variants": {
"variant_untracked_id": "", "variant_untracked_id": "",
"variant_inventory1_id": "", "variant_inventory1_id": "",
"variant_soldout_id": "" "variant_soldout_id": ""
}, },
"collection_id": "", "collection_id": "",
=======
"collection_id": "109931075",
>>>>>>> Stashed changes
"gift_cards": { "gift_cards": {
"valid11": { "ValidGiftCard11": {
"id": "8366979", "id": "",
"code": "ValidGiftCard11", "code": "",
"value": 11 "value": 11
}, },
"valid25": { "ValidGiftCard25": {
"id": "7441155", "id": "",
"code": "ValidGiftCard25", "code": "",
"value": 25 "value": 25
}, },
"valid50": { "ValidGiftCard50": {
"id": "7438659", "id": "",
"code": "ValidGiftCard50", "code": "",
"value": 50 "value": 50
}, },
"expired": { "expired": {
"id": "7438723", "id": "",
"code": "ExpiredGiftCard25", "code": "",
"value": 25 "value": 0
}, },
"invalid": { "invalid": {
"id": "42424242", "id": "",
"code": "InvalidGiftCard42", "code": "",
"value": 42 "value": 0
} }
}, },
"discounts": { "discounts": {
"expired": { "expired": {
"code": "expired_discount", "code": "",
"value": 1 "value": 0
}, },
"valid": { "valid": {
"code": "12_dollar_discount", "code": "",
"value": 12 "value": 0
} }
} }
} }
\ No newline at end of file
...@@ -96,20 +96,77 @@ Initialize the `BUYClient` with your credentials from the *Mobile App Channel* ...@@ -96,20 +96,77 @@ Initialize the `BUYClient` with your credentials from the *Mobile App Channel*
BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com" BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com"
apiKey:@"aaaaaaaaaaaaaaaaaa" apiKey:@"aaaaaaaaaaaaaaaaaa"
channelId:@"99999"]; channelId:@"99999"];
```
### Storefront API
After initializing the client with valid shop credentials, you can begin fetching collections.
```objc
[client getCollections:^(NSArray<BUYCollection *> *collections, NSError *error) {
if (collections && !error) {
// Do something with collections
} else {
NSLog(@"Error fetching collections: %@", error.userInfo);
}
}];
```
Having a collection, we can then retrieve an array of products within that collection:
```objc
BUYCollection *collection = collections.firstObject;
[client getProductsPage:0 inCollection:collection.collectionId completion:^(NSArray<BUYProduct *> *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
if (products && !error) {
// Do something with products
} else {
NSLog(@"Error fetching products in collection %@: %@", collection.collectionId, error.userInfo);
}
}];
```
// Fetch your products ### Customer API
[self.client getProductsPage:1 completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) { ##### Customer Login
if (error) { You can allow customers to login with their existing account using the SDK. First, we'll need to create the `BUYAccountCredentials` object used to pass authentication credentials to the server.
NSLog(@"Error retrieving products: %@", error.userInfo); ```objc
NSArray *credentialItems = @[
[BUYAccountCredentialItem itemWithEmail:@"john.smith@gmail.com"],
[BUYAccountCredentialItem itemWithPassword:@"password"],
];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];
```
We can now use the credentials object to login the customer.
```objc
[client loginCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) {
if (customer && token && !error) {
// Do something with customer and store token for future requests
} else { } else {
for (BUYProduct *product in products) { NSLog(@"Failed to login customer: %@", error.userInfo);
NSLog(@"%@", product.title);
} }
}];
```
##### Customer Creation
Creating a customer account is very similar to login flow but requres a little more info in the credentials object.
```objc
NSArray *credentialItems = @[
[BUYAccountCredentialItem itemWithFirstName:@"John"],
[BUYAccountCredentialItem itemWithLastName:@"Smith"],
[BUYAccountCredentialItem itemWithEmail:@"john.smith@gmail.com"],
[BUYAccountCredentialItem itemWithPassword:@"password"],
[BUYAccountCredentialItem itemWithPasswordConfirmation:@"password"],
];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];
```
After we obtain the customers first name, last name and password confirmation in addition to the email and password fields, we can create an account.
```objc
[client createCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) {
if (customer && token && !error) {
// Do something with customer and store token for future requests
} else {
NSLog(@"Failed to create customer: %@", error.userInfo);
} }
}]; }];
``` ```
Consult the [Usage Section](https://docs.shopify.com/mobile-buy-sdk/ios/integration-guide/#using-the-mobile-buy-sdk) of the Integration Guide on how to create a cart, and checkout with the SDK. ### Integration Guide
Consult the [Usage Section](https://docs.shopify.com/mobile-buy-sdk/ios/integration-guide/#using-the-mobile-buy-sdk) of the Integration Guide on how to create a cart, checkout and more with the SDK.
### Building the SDK ### Building the SDK
......
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