simpl-ios-sdk-dist-ios7
如何安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 GetSimpl 集成到您的 Xcode 项目中,在 Podfile 中指定它
pod 'GetSimpl-iOS'
然后,运行以下命令
$ pod install
iOS 集成
-
目标 -> 编译设置 -> ENABLE_BITCODE -> 标记为 NO。
-
将以下内容添加到您的 Info.plist 文件中
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>smpYourMerchantID</string>
</array>
</dict>
</array>
请注意,您必须在 smpYourMerchantID
中添加您的 merchantID,例如 smp55d72761ec60ytbnk97414182
。
- 对于 iOS 9+,也请在您的 Info.plist 文件中添加以下内容
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>getsimpl.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>simplApp</string>
</array>
- 开发者可以像下面这样在沙盒或生产环境之间切换
[GSManager enableSandBoxEnvironment:YES]
如何使用
- 导入库
#import "GetSimpl-iOS/GetSimpl.h"
- 使用您的商户ID初始化SDK,通常在应用的 didFinishLaunchingOptions 方法中
[GSManager initializeWithMerchantID@:@"Your merchant id"];
- 检查用户是否预先批准
GSUser *user = [[GSUser alloc] initWithPhoneNumber:@"user mobile number" email:@"user email"];
[[GSManager sharedManager] checkApprovalForUser:user onCompletion:^(BOOL approved, BOOL isFirstTransactionOfUser, NSString *buttonText ,NSError *error) {
}]
Bool approved : If GSUser is pre-approved or not
Bool isFirstTransactionOfUser : If user has already done transactions previously or not
String/NSString buttonText : The text to display on Simpl button. If GSUser is pre-approved,this will contain a value specific to merchant with default value of "Buy Now, Pay Later". Will be nil if GSUser is not pre-approved.
NSError error : Error if any
如果用户被批准并且商户应显示Simpl按钮,如果用户没有被批准,则不要显示Simpl按钮。
-
要显示Simpl选项,商户可以使用自己的自定义按钮。不过他们应使用上述批准调用中的
buttonText
值来显示按钮上的文本。 -
点击Simpl按钮时,调用以下方法开始交易。这将打开一个视图供用户输入OTP。在完成块中,将返回 transaction_token。
GSUser *user = [[GSUser alloc] initWithPhoneNumber:@"user mobile number" email:@"user email"];
// OrderId refers to the merchant generated order id of the transaction in progress
NSDictionary *additionalParams = @{@"order_id": @"merchant order id"};
[user setHeaderParams:additionalParams];
GSTransaction *transaction = [[GSTransaction alloc] initWithUser:user amountInPaise:500];
[[GSManager sharedManager] authorizeTransaction:transaction onCompletion:^(NSDictionary * jsonResponse, NSError * error) {
}];
在发起 authorizeTransaction 调用之前,GSUser 的电话号码必须被设置。一旦你有了 transaction_token,将它传递到你的服务器,服务器随后可以将交易详情传递给 Simpl。