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",
<<<<<<< Updated upstream
"shop_domain": "",
"api_key": "",
"channel_id": "",
......@@ -8,64 +7,51 @@
"merchant_id": "",
"customer_email": "",
"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": [
"2096060931",
"2096063363",
"2096062275",
"2096057987"
"",
""
],
<<<<<<< Updated upstream
"variants": {
"variant_untracked_id": "",
"variant_inventory1_id": "",
"variant_soldout_id": ""
},
"collection_id": "",
=======
"collection_id": "109931075",
>>>>>>> Stashed changes
"gift_cards": {
"valid11": {
"id": "8366979",
"code": "ValidGiftCard11",
"ValidGiftCard11": {
"id": "",
"code": "",
"value": 11
},
"valid25": {
"id": "7441155",
"code": "ValidGiftCard25",
"ValidGiftCard25": {
"id": "",
"code": "",
"value": 25
},
"valid50": {
"id": "7438659",
"code": "ValidGiftCard50",
"ValidGiftCard50": {
"id": "",
"code": "",
"value": 50
},
"expired": {
"id": "7438723",
"code": "ExpiredGiftCard25",
"value": 25
"id": "",
"code": "",
"value": 0
},
"invalid": {
"id": "42424242",
"code": "InvalidGiftCard42",
"value": 42
"id": "",
"code": "",
"value": 0
}
},
"discounts": {
"expired": {
"code": "expired_discount",
"value": 1
"code": "",
"value": 0
},
"valid": {
"code": "12_dollar_discount",
"value": 12
"code": "",
"value": 0
}
}
}
\ No newline at end of file
......@@ -96,20 +96,77 @@ Initialize the `BUYClient` with your credentials from the *Mobile App Channel*
BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com"
apiKey:@"aaaaaaaaaaaaaaaaaa"
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
[self.client getProductsPage:1 completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
if (error) {
NSLog(@"Error retrieving products: %@", error.userInfo);
### Customer API
##### Customer Login
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.
```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 {
for (BUYProduct *product in products) {
NSLog(@"%@", product.title);
NSLog(@"Failed to login customer: %@", error.userInfo);
}
}];
```
##### 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
......
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