NAV

Welcome

Walmart SDK is designed to let you drive sales right in your app or on your website. SDK components like BuyNow button can be placed next to a product offering on the website or in a mobile application and it can be configured to directly add the product to the cart on Walmart.com. With the Buy Now button, you can remove friction in purchase by reducing the number of steps required for a consumer to purchase an item from walmart.com and hence see an increased conversion rate.

This page provides in-depth documentation on Walmart SDK features and is meant to be a guide for developers integrating the SDK and app makers seeking to engage with their users.

Getting Started for iOS

You can integrate the Walmart SDK with your iOS app. This will let you drive sales and your app users will be able to buy from Walmart quickly. A good way to start is to follow this quick tutorial. In the later part of this tutorial we have also provided source code examples for both Objective-C and Swift.

Prerequisites

Install SDK

Installation with CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects.You can install it with the following command:

$ gem install cocoapods (CocoaPods 1.0.0+ is required to build WalmartBuynowSDK 1.1.0)

Podfile

To integrate WalmartBuynowSDK into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0' target 'MyApp' do pod 'WalmartBuynowSDK', '~> 1.1.0'
end

If you are using Swift, be sure to add use_frameworks! and set your target to iOS 8+:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks! target 'MyApp' do pod 'WalmartBuynowSDK', '~> 1.1.0'
end

Then, run the following command:

$ pod install

Configure your Xcode Project

Once pod install succeed, use Xcode to reopen the .xcworkspace.
You will need a publisher Id to use the SDK. This is either provided by Walmart or if you are a Impact Radius publisher, then Impact Radius publisher Id can be used. Now configure the .plist for your project:

  1. In Xcode right-click your .plist file and choose Open As Source Code.
  2. Copy & Paste the XML snippet into the body of your file (<dict>...</dict>).

    <key>WalmartPublisherId</key>
    <string>{your-publisher-id}</string>
    
  3. Replace:

    {your-publisher-id} with your publisher Id

For iOS 9 only: Whitelist Walmart Servers

If you compile your app with iOS SDK 9.0, you will be affected by App Transport Security. Currently, you will need to whitelist Walmart domains in your app by adding the following to your application’s plist

<key>NSAppTransportSecurity</key>
<dict> <key>NSExceptionDomains</key> <dict> <key>walmart.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> </dict>
</dict>

Initialize Walmart SDK

Now that you have covered all the above steps and successfully installed the SDK, you’ll need to initialize it first in your app to use it. A good place to do that is in your AppDelegate’s application (_:didFinishLaunchingWithOptions:) method. You can also configure other settings of the SDK there as well. Please go through the detailed Reference docs for iOS for available settings.

Code Example

#import "AppDelegate.h"
@import WalmartSDKKit; @interface AppDelegate ()
@end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[WMTSDK sharedInstance]initSDK]; [WMTLogger defaultLogger].logLevel = WMTLogLevelError; return YES;
}
......
import UIKit
import WalmartBuynowSDK @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { WMTSDK.sharedInstance().initSDK() WMTLogger.default().logLevel = WMTLogLevel.error return true } ......

Walmart BuyNow Button

The Walmart BuyNow button is a way to drive the user to the walmart.com product details page or to directly add the products to the cart on Walmart.com opened in-app.

Add Walmart BuyNow button to your application

Walmart BuyNow Button Flow

General iOS Setup

Complete the Getting Started Guide for Walmart iOS SDK before adding the Walmart BuyNow button. The guide will include:

Add Walmart BuyNow Button Code

You can add the Walmart BuyNow button to your view like you would do with any other UIView. Create a new BuyNow button object WMTBuyNowControl along with the productIds as shown in the code example shown below.


// ViewController.m example #import "ViewController.h"
@import WalmartBuynowSDK; @interface ViewController()
@end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; WMTItem *item1 = [WMTItem createItemWithItemId:@"54518466" itemIdType:WMTItemIdTypeWalmartId]; WMTItem *item2 = [WMTItem createItemWithItemId:@"16207314" itemIdType:WMTItemIdTypeWalmartId]; WMTLineItem *lineItem1 = [WMTLineItem createItemWithWMTItem:item1 quantity:1]; WMTLineItem *lineItem2 = [WMTLineItem createItemWithWMTItem:item2 quantity:1]; NSSet *wmtLineItemsSet = [NSSet setWithObjects:lineItem1,lineItem2, nil]; buyNowButton = [[WMTBuyNowControl alloc]initWithWMTLineItems:wmtLineItemsSet]; buyNowButton.center = self.view.center; [self.view addSubview:buyNowButton];
} @end 

// ViewController.swift example
import UIKit
import WalmartBuynowSDK class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let item1 = WMTItem(itemId: "54518466", itemIdType: WMTItemIdType.walmartId) let item2 = WMTItem(itemId: "16207314", itemIdType: WMTItemIdType.walmartId) let lineItem1 = WMTLineItem(wmtItem: item1, quantity: 1) let lineItem2 = WMTLineItem(wmtItem: item2, quantity: 1) let wmtLineItemsSet: Set = [lineItem1, lineItem2] let buyNowButton = WMTBuyNowControl(wmtLineItems: wmtLineItemsSet as? Set<WMTLineItem>) buyNowButton?.center = self.view.center self.view.addSubview(buyNowButton!) }
} 

Customize Walmart BuyNow button

You can customize the Walmart BuyNow button size and color using the options shown in the following table.

SizeOrange - Default ColorBlue Color
Primary - Default
Compact
Mini
// Change Size to Compact Scheme
buyNowButton.sizeScheme = WMTButtonSizeSchemeCompact; // Change Color to Blue Scheme
buyNowButton.colorScheme = WMTButtonColorSchemeBlue;
// Change Size to Compact Scheme
buyNowButton.sizeScheme = WMTButtonSizeScheme.Compact; // Change Color to Blue Scheme
buyNowButton.colorScheme = WMTButtonColorScheme.Blue;

Once you have created a BuyNow button it is also possible to add or remove associated Walmart Items. See the code example below:

// Add a single product
[buyNowButton addWMTItem:{WMTItem} withQuantity:{quantity}]; // Or Remove a single product
[buyNowButton removeWMTItem:{WMTItem} withQuantity:{quantity}];
// Add a single product
buyNowButton.addWMTItem({WMTItem}, withQuantity: {quantity}) // Or Remove a single product
buyNowButton.removeWMTItem({WMTItem}, withQuantity: {quantity}) 

Sample IOS App

You can download the Demo code, check its source code and run it to get a sense of how to use the SDK.