Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Core SDK Integration Instruction

Step 1: Add Core SDK

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 with Cocoapods:

  1. Install CocoaPods 0.39.0 or later
  2. In your Podfile, add pod 'PWCoreSDK' and pod 'PW[Local payment method]Plugin'(optional) to your main and test targets
  3. From the command line, run pod install
  4. Use the .xcworkspace file generated by CocoaPods
  5. Make sure you have -ObjC in Other Linker Flags in your project's Build settings
  6. If you are using Swift, create a new Objective-C file in order to create new bridging-header.h files, then import the following files into the header file like:
#import <PWCoreSDK/PWCoreSDK.h>

Install as Static library:

  1. Download the latest release of the SDK and extract the zip.
  2. Go to your Xcode project’s General settings. Drag libPWCoreSDK.a and other plugin library to the “Linked frameworks and libraries” section under your project directory. Make sure to copy items which are selected and click Finish.
  3. In your unit test target’s “Build Settings”, add the parent path to libPWCoreSDK.a in the Library Search Paths section.
  4. Drag the bundle into your Copy bundle resources in project's Build phase
  5. Add -ObjC to Other Linker Flags in your project's Build settings
  6. If you are using Swift, create a new Objective-C file in order to create new bridging-header.h files, then import the following files into the header file like:
#import <PWCoreSDK/PWCoreSDK.h>

Step 2: Setup Core SDK

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.

Step 3: Extra Settings (Optional)

  • 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 as PWPaymentResponseCodeMerchantProcessing or PWPaymentResponseCodeSignatureRequiring.
  • Default UI of the SDK is flat style, to use game UI, check PWGameUIPlugin

Step 4: Add Payment Methods

You can choose one or more payment methods according to your needs.

Step 5: Create new payment

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"

Step 6: Present View Controller

Present Payment options view controller:

let options = [brick, mint, mobiamo, widget]
PWCoreSDK.sharedInstance().showPaymentVC(withParentVC: self, paymentObject: payment, paymentOption: options, delegate: self)

Step 7: Handle callback URL

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
}

Step 8: Handle Payment Response

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
    }
}

Step 9: Customized UI

Usage:

let custom = PWCustomization()
//Config properties...
PWCoreSDK.sharedInstance().setCustomizationForDefaultUI(custom)

customization_guide

Payment Methods Integration Details

Brick

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 errorMessage will 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 pass SUCCESS/FAILED back 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 chargeObject as Dictionary, Charge object format can be found in our Brick docs

PWLocal - PWOptionWidget

Create PWOptionWidget

let widgetFlex = PWWidgetDigitalGoodsFlexible()
widgetFlex.widget = "m2_1"
widgetFlex.ag_type = "fixed"

let widget = PWOptionWidget(type: PWWidgetType.digitalGoodsFlexible, extraParams: widgetFlex)

Value for type: PWWidgetType enum

Note: extraParams can 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 in PaymentObject

Mint

Create PWOptionMint

let mint = PWOptionMint()

Mobiamo

Create PWOptionMobiamo

let mobiamo = PWOptionMobiamo()
mobiamo.useNoPrice = true

If useNoPrice is set to true: Default Mobiamo price points will be used for each country. If useNoPrice is omitted: The price will be shown as you set in SDK.

External Payment Methods

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 payments together 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.