How To Implement A Store In Your App (And Still Get Approved)

While developing Lifelapse for iPhone, one of the things we ran into was how to implement a Lifepouch store in our app without using Apple’s in-app purchases. To share our experiences, I’ll show you step by step how we managed to implement a Shopify store into our app. I also shared the code on Github, which you can find later in the article.

If you sell physical products next to your iPhone application, you might want to consider creating an in-app store, as almost 20% of every Lifepouch we sold was purchased using our in-app store.

We distribute our physical product, the Lifepouch, via Shopify. We chose Shopify because of its easy setup and, best of all, they offer an API to connect the store to your own (digital) product. If you’d like to try Shopify, sign up here.

Let’s dive in to the technical part while we’re at it.

I created a Shopify API wrapper that illustrates how to get your shop’s products with one single call using ASIHTTPRequest with block-based callbacks, TouchJSON and delegation. You can download LLStoreWrapper from my personal Github account here.

You start with creating a new private Shopify application by going to the Manage Apps page on the Apps tab in your Shopify admin page.

Manage Shopify AppsThen, click the “Click here” link at the bottom of the page to create a new private application for your Shopify store.

Create a private Shopify app

Generate a new Shopify application, go to Xcode and copy the API credentials into LLStoreWrapper.m.

Shopify API Credentials
Your store’s products are retrieved using the following code:
LLStoreWrapper *storeWrapper = [[[LLStoreWrapper alloc] init] autorelease];
[storeWrapper setDelegate:self];
[storeWrapper getProducts];

If the storeWrapper succeeds in getting the products from Shopify, it will make a delegate call that contains an array with products:
-(void)storeWrapper:(LLStoreWrapper *)storeWrapper finishedGettingProducts:(NSArray *)products {
//You can log the products by doing NSLog(@"%@", products);
}

If the storeWrapper fails, the following delegate method will be called containing a NSDictionary with the failure reason.
-(void)storeWrapper:(LLStoreWrapper *)storeWrapper failedGettingProducts:(NSDictionary *)failure;

The finishedGettingProducts call will return all the data about the products on your shopify store in full detail. You could use the products array to populate a UITableView and create a productDetailViewController using an object from the products array.

However, there’s one tiny issue regarding the Shopify API. Shopify doesn’t provide an API call for creating orders. That makes the entire purpose of the shop kind of useless right? Well, no.

I realized that Shopify probably stores the user’s cart in a cookie on the device. Voilà, you have yourself an “Add to Cart” API call. Problem solved.

You can create an order using the following code:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.YOURSTORENAME.com/cart/add/"]];
[request setRequestMethod:@"POST"];
[request setPostValue:productID forKey:@"id"];
[request setTimeOutSeconds:30];
[request startAsynchronous];

This call will tell Shopify to add a product to the user’s cart with the id of the product that you provide in [request setPostValue:forKey:@"id"]; When the request finishes, you can create a UIWebView and load http://www.YOURSTORENAME.com/cart/. This will show your Shopify cart page with the product you selected.

This completes my quick tutorial on how I created an in-app store for our Lifelapse iPhone application without using in-app purchases. I’d like to thank Shopify for their amazing online store platform and the creators of ASIHTTPRequest and TouchJSON, for their extremely useful classes.

To give the store a test drive, download Lifelapse for iPhone from the App Store.

Downloads & Links

ASIHTTPRequest by All-Seeing Interactive
TouchJSON by TouchCode
LLStoreWrapper by Glenn Wolters for Lifelapse

Shopify API Documentation
Signup for a Shopify account

This entry was posted in Development, Lifelapse for iPhone. Bookmark the permalink.

11 Responses to How To Implement A Store In Your App (And Still Get Approved)

  1. Pingback: 4 Ways In-App Purchasing Will Change Mobile

  2. Pingback: 4 Ways In-App Purchasing Will Change Mobile | ShoutReview

  3. Pingback: 4 Ways In-App Purchasing Will Change Mobile | Ruturaj Pradeep Kohok | Your Web Advisor

  4. Pingback: 4 Ways In-App Purchasing Will Change Mobile | Economics of Android

  5. Pingback: 4 Ways In-App Purchasing Will Change Mobile « Tablet Design

  6. Pingback: CitiPrice Internet Properties » 4 Ways In-App Purchasing Will Change Mobile

  7. Pingback: 4 Ways In-App Purchasing Will Change Mobile - Programming Blog

  8. Pingback: 4 Ways In-App Purchasing Will Change Mobile | CashKlick

  9. Pingback: » 4 Ways In-App Purchasing Will Change Mobile 50psi

  10. Pingback: Mobile News and Reviews » 4 Ways In-App Purchasing Will Change Mobile

  11. Nice work! I’ll ping some other folks at Shopify to get a blog post about this up to echo yours.

    There are a few other ways of remotely adding products to Shopify’s cart; check them out here: http://wiki.shopify.com/Adding_to_the_Cart_from_a_remote_website

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>