Our SDK is delivered as static library or public repository.
Note: If your CoreSDK got updated, you should also check to update the rest of plugins.
- Install CocoaPods 0.39.0 or later
- In your Podfile, add
pod 'PWCoreSDK'andpod 'PW[Local payment method]Plugin'(optional) to your main and test targets - From the command line, run
pod install - Use the .xcworkspace file generated by CocoaPods
- Make sure you have
-ObjCinOther Linker Flagsin your project's Build settings - If you are using Swift, create a new Objective-C file in order to create new
bridging-header.hfiles, then import the following files into the header file like:
#import <PWCoreSDK/PWCoreSDK.h>- Download the latest release of the SDK and extract the zip.
- Go to your Xcode project’s
Generalsettings. DraglibPWCoreSDK.aand other plugin library to the “Linked frameworks and libraries” section under your project directory. Make sure to copy items which are selected and clickFinish. - In your unit test target’s “Build Settings”, add the parent path to
libPWCoreSDK.ain theLibrary Search Pathssection. - Drag the bundle into your
Copy bundle resourcesin project'sBuild phase - Add
-ObjCtoOther Linker Flagsin your project's Build settings - If you are using Swift, create a new Objective-C file in order to create new
bridging-header.hfiles, then import the following files into the header file like:
#import <PWCoreSDK/PWCoreSDK.h>PWCoreSDK.sharedInstance().setGlobalProjectKey("YOUR_PUBLIC_KEY")Project key: All payment option will use this Project key if you don't override Project key while declaring them.
setGlobalSecretKey: Some payment option will require signing the request to continue payment. You can specify your project's secret key here so that the SDK can help you sign the request to continue.setGlobalSignType: Specify the signature algorithm that you wanted to use.setRequestTimeOut: Request time out for the request in second. Also apply for delegate callback that require futher action such asPWPaymentResponseCodeMerchantProcessingorPWPaymentResponseCodeSignatureRequiring.- Default UI of the SDK is flat style, to use game UI, check PWGameUIPlugin
You can choose one or more payment methods according to your needs.
Create new payment with PaymentObject class:
let payment = PWPaymentObject()
payment.currency = "USD"
payment.price = NSDecimalNumber(string: "0.99")
payment.userID = "testuid"
payment.itemID = "testid"
payment.name = "test"Present Payment options view controller:
let options = [brick, mint, mobiamo, widget]
PWCoreSDK.sharedInstance().showPaymentVC(withParentVC: self, paymentObject: payment, paymentOption: options, delegate: self)Add this code in your AppDelegate to handle callback from other app if you use plugins (suchs as Alipay, Unionpay, Paypal,...)
func application(_ app: UIApplication, open url: URL, options:[UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
PWCoreSDK.sharedInstance().handlePingbackURL(url)
return true
}Implement PWCoreSDKDelegate protocol to handle payment response:
func paymentResponse(_ response: PWCoreSDKResponse) {
switch response.responseCode {
case .successful: //Payment is successful
case .failed: //Payment is failed, the SDK will show error popup automatically if this happen
case .cancel: //Payment is cancelled
case .signatureRequiring: //Only need to handle this case if you didn't provide the SDK with your Secret key
switch response.signatureAlgorithm {
case .MD5:
PWCoreSDK.sharedInstance().continuePayment(withSign: md5("\(response.stringToSign!)YOUR_SECRET_KEY"))
case .SHA256:
PWCoreSDK.sharedInstance().continuePayment(withSign: sha256("\(response.stringToSign!)YOUR_SECRET_KEY"))
}
case .merchantProcessing: //Some option will require you to process it futher from your backend, such as Brick, refer below on how to handle them
}
}Usage:
let custom = PWCustomization()
//Config properties...
PWCoreSDK.sharedInstance().setCustomizationForDefaultUI(custom)Step 1: Create PWOptionBrick
let brick = PWOptionBrick()
brick.setCardScannerPlugin(PWCardScannerPlugin())PWCardScannerPlugin is a plugin that will help your user to scan their credit card without manually input, powered by Card.io
Step 2: Handle One Time Token
One-time token is automatically obtained by the SDK. After the token is successfully fetched, the response: PWCoreSDKResponse will contain the token: BrickToken along with it.
Step 3: Create A Charge
After obtaining one-time token, send a request from backend to Paymentwall server to create a charge.
POST request to: https://api.paymentwall.com/api/brick/charge
Parameters and description can be referred here.
Step 4: Handle Charge Response
case .merchantProcessing:
if response.paymentType == PWPaymentTypeBrick {
//Process the one-time token in your backend asynchronously
//After finish:
brick.handleBackendChargeResult(true, chargeObject: nil, secureURL: nil, errorMessage: nil)
}-
Pass the
errorMessagewill make the SDK will automatically show failed dialog instead of successful dialog -
If 3D secure is necessary, pass the URL in
secureURL, the SDK will automatically show the 3D secure page and passSUCCESS/FAILEDback to app after user finishes entering secure info -
If you want to enable store card feature for user, pass the Charge object to our SDK via
chargeObjectas Dictionary, Charge object format can be found in our Brick docs
Create PWOptionWidget
let widgetFlex = PWWidgetDigitalGoodsFlexible()
widgetFlex.widget = "m2_1"
widgetFlex.ag_type = "fixed"
let widget = PWOptionWidget(type: PWWidgetType.digitalGoodsFlexible, extraParams: widgetFlex)Value for
type:PWWidgetTypeenum
Note:
extraParamscan be Dictionary or any of the defined class:PWWidgetDigitalGoodsFlexible,PWWidgetDigitalGoodsDefaut,PWWidgetVirtualCurrency,PWWidgetCart, refer their headers for required property or PWLocal docs. Key and value like prices, amount, currencyCode, currencies, ag_name, ag_external_id, uid will be ignored and use the one you described inPaymentObject
Create PWOptionMint
let mint = PWOptionMint()Create PWOptionMobiamo
let mobiamo = PWOptionMobiamo()
mobiamo.useNoPrice = trueIf
useNoPriceis set totrue: Default Mobiamo price points will be used for each country. IfuseNoPriceis omitted: The price will be shown as you set in SDK.
Paymentwall SDK supports external payment system injection (which are in our defined payment system (PS) list). Each time you want to add a new payment system, you have to include its native SDK into your project along with our plugin framework. Our framework will handle creating all the necessary parameters then you can use them to show the native local payment SDK:
Step 1: Add Payment options to Core SDK
//You can pass it along with core sdk options array
let options = [brick, mint, mobiamo, widget, alipay, mycard, wechatpay]Note: These payment options will be placed in
Local paymentstogether with PWOptionWidget.
Step 2: Import Plugin SDK
Add the plugin by Cocoapods with pod 'PW[Local payment method]Plugin' or manually drag the PW[Local payment method]Plugin.a and its headers file to your project.
Step 3: Import Header File
Import the library header into your project or via bridging-headers.h if you use Swift
Step 4: Set Up Plugin
Each plugin has different requirements. Details can be found in their headers or detailed docs below.
Note: All plugins support your own signature string if you don't specify Secret key in both CoreSDK and PluginSDK.
