The WePay iOS SDK enables collection of payments via various payment methods.
It is meant for consumption by WePay partners who are developing their own iOS apps aimed at merchants and/or consumers.
Regardless of the payment method used, the SDK will ultimately return a Payment Token, which must be redeemed via a server-to-server API call to complete the transaction.
Payment methods
There are two types of payment methods:
Consumer payment methods - to be used in apps where consumers directly pay and/or make donations
Merchant payment methods - to be used in apps where merchants collect payments from their customers
The WePay iOS SDK supports the following payment methods
Card Reader: Using an EMV Card Reader, a merchant can accept in-person payments by prosessing a consumer's EMV-enabled chip card. Traditional magnetic stripe cards can be processed as well.
Manual Entry (Consumer/Merchant): The Manual Entry payment method lets consumer and merchant apps accept payments by allowing the user to manually enter card info.
Unzip the file and copy the contents anywhere inside your project directory
In Xcode, go to your app's target settings. On the Build Phases tab, expand the Link Binary With Libraries section.
Include the following iOS frameworks:
AudioToolbox.framework
AVFoundation.framework
CoreBluetooth.framework
CoreLocation.framework
CoreTelephony.framework
ExternalAccessory.framework
MediaPlayer.framework
SystemConfiguration.framework
UIKit.framework
libstdc++.6.0.9.dylib
libstdc++.dylib
libz.dylib
Also include the framework files you copied:
WePay.framework
Done!
Note: Card reader functionality is not available in this SDK by default. If you are interested in using the WePay Card Reader, please contact your sales representative or account manager. If you have yet to be in direct contact with WePay, please email sales.nosp@m.@wep.nosp@m.ay.co.nosp@m.m.
WePay.h is the starting point for consuming the SDK, and contains the primary class you will interact with. It exposes all the methods you can call to accept payments via the supported payment methods. Detailed reference documentation is available on the reference page for the WePay class.
Delegate protocols
The SDK uses delegate protocols to respond to API calls. You must adopt the relevant protocols to receive responses to the API calls you make. Detailed reference documentation is available on the reference page for each protocol:
All other classes in the SDK are data models that are used to exchange data between your app and the SDK. Detailed reference documentation is available on the reference page for each class.
Next Steps
Head over to the documentation to see all the API methods available. When you are ready, look at the samples below to learn how to interact with the SDK.
Error Handling
WPError.h serves as documentation for all errors surfaced by the WePay iOS SDK.
Samples
See the WePayExample app for a working implementation of all API methods.
See the SwiftExample app for a working implementation of all API methods in a Swift 3 application. Note: make sure to open the project using SwiftApp.xcworkspace and not SwiftApp.xcodeproj.
Initializing a Bridging Header (for Swift apps)
For using Objective-C modules in a Swift application, you will need to create a bridging header.
Make sure you are working in {app_name}.xcworkspace file.
Under your target application folder, create a header file: {app_name}-Bridging-Header.h
In the Header file, import the modules you need:
#import <WePay/WePay.h>
Click on the main application project to get to Build Settings.
Search for bridging header in your target application to find a setting called Swift Compiler - Code Generation.
Double click in the column next to Objective-C Bridging Header and add your Header file: {app_name}/{app_name}-Bridging-Header.h
There's no need to import the module in your code; you can use the module by calling it directly in your Swift application.
(optional) Providing permission to use location services for fraud detection
In Xcode, go to your projects settings. On the Build Phases tab, expand the Link Binary With Libraries section and include the CoreLocation.framework iOS framework.
Open your app's Info.plist file and add entries for NSLocationUsageDescription and NSLocationWhenInUseUsageDescription.
// Show UI asking the user to insert the card reader and wait for it to be ready
That's it! The following sequence of events will occur:
The user inserts the card reader (or it is already inserted), or powers on their bluetooth card reader.
The SDK tries to detect the card reader and initialize it.
The cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusSearching.
If any card readers are discovered, the selectCardReader: method will be called with an array of discovered devices. If anything is plugged into the headphone jack, "AUDIOJACK" will be one of the devices discovered.
If no card readers are detected, the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusNotConnected.
Once the card reader selection completion block is called, the SDK will attempt to to connect to the selected card reader.
If the card reader is successfully connected, then the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusConnected.
Next, the SDK checks if the card reader is correctly configured (the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusCheckingReader).
If the card reader is already configured, the app is given a chance to force configuration. The SDK calls the shouldResetCardReaderWithCompletion: method, and the app must execute the completion method, telling the SDK whether or not the reader should be reset.
If the reader was not already configured, or the app requested a reset, the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusConfiguringReader and the card reader is configured.
Next, if the card reader is successfully initialized, the SDK asks the app for transaction information by calling the authorizeAmountWithCompletion: method. The app must execute the completion method, telling the SDK what the amount, currency code and merchant account id is.
Next, the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusWaitingForCard.
If the user swipes a card successfully:
The cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusSwipeDetected.
The SDK attempts to ask the app for the payer’s email by calling the insertPayerEmailWithCompletion: method. If the app implements this optional delegate method, it must execute the completion method and pass in the payer’s email address.
The didReadPaymentInfo: method is called with the obtained payment info.
The cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusTokenizing, and the SDK will automatically send the obtained card info to WePay's servers for tokenization.
If tokenization succeeds, the paymentInfo:didTokenize: method will be called.
If tokenization fails, the paymentInfo:didFailTokenization: method will be called with the appropriate error, and processing will stop.
Instead, if the user dips a card successfully:
The cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusCardDipped
If the card has multiple applications on it, the payer must choose one:
The SDK calls the selectEMVApplication:completion: method with a list of Applications on the card.
The app must display these Applications to the payer and allow them to choose which application they want to use.
Once the payer has decided, the app must inform the SDK of the choice by executing the completion method and passing in the index of the chosen application.
Next, the SDK obtains card data from the chip on the card.
The SDK attempts to ask the app for the payer’s email by calling the insertPayerEmailWithCompletion: method. If the app implements this optional delegate method, it must execute the completion method and pass in the payer’s email address.
The didReadPaymentInfo: method is called with the obtained payment info.
The cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusAuthorizing, and the SDK will automatically send the obtained EMV card info to WePay's servers for authorization.
If authorization succeeds, the paymentInfo:didAuthorize: method will be called and processing will stop.
If authorization fails, the paymentInfo:didFailAuthorization: method will be called.
If a recoverable error occurs during swiping or dipping, one of the failure methods will be called. After a few seconds, the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusWaitingForCard and the card reader will again wait for the user to swipe/dip a card.
If an unrecoverable error occurs, or if the SDK is unable to obtain data from the card, one of teh failure methods will be called with the appropriate error.
When processing stops, the cardReaderDidChangeStatus: method will be called with status = kWPCardReaderStatusStopped.
Done!
Note: After the card is dipped into the reader, it must not be removed until a successful auth response (or an error) is returned.
// Note: the virtualTerminal parameter above should be set to YES if a merchant is collecting payments manually using your app. It should be set to NO if a payer is making a manual payment using your app.
Make the WePay API call, passing in the instance of the class that implemented the WPTokenizationDelegate protocol
That's it! The following sequence of events will occur:
The SDK will attempt to read the battery level of the card reader
If the operation succeeds, WPBatteryLevelDelegate's didGetBatteryLevel: method will be called with the result
Otherwise, if the operation fails, WPBatteryLevelDelegate's didFailToGetBatteryLevelwithError: method will be called with the appropriate error
Configuring the SDK
The experiences described above can be modified by utilizing the configuration options available on the WPConfig object. Detailed descriptions for each configurable property is available in the documentation for WPConfig.
Test/develop using mock card reader and mock WepayClient
To use mock card reader implementation instead of using the real reader, instantiate a MockConfig object and pass it to Config: