GetSimpl 1.2.4

GetSimpl 1.2.4

测试已测试
Lang语言 Obj-CObjective C
许可证 商业
发布上次发布2016年3月

Alok Jha维护。



GetSimpl 1.2.4

  • 作者:
  • Alok Jha

simpl-ios-sdk-dist

注意:此存储库提供的框架仅支持iOS 8.0及以上版本。如果需要支持iOS 7.0,请访问此存储库以使用静态库方法。

如何安装

手动安装

转到存储库发布部分,从最新版本下载GetSimpl.framework.zip文件,解压它以获取最新的框架文件。

iOS集成

  • 您获得SDK后,将GetSimpl框架添加到Xcode项目。当Xcode显示添加文件的选项时,请确保勾选“如果需要则复制项目”。
  • 目标 -> 一般 -> 嵌入式框架 -> 点击"+"图标添加GetSimpl框架。
  • 转到构建设置 -> 构建选项 -> 嵌入内容包含Swift代码设置为YES。
  • 将以下内容添加到Info.plist文件中
    <key>CFBundleURLTypes</key>
    <array>
     <dict>
        <key>CFBundleURLSchemes</key>
        <array>
        // smp + YourMerchantID, like; smp55d72761ec60ytbnk97414182
        <string>smpYourMerchantID</string>
       </array>
     </dict>
    </array>
  • 对于iOS 9,也需要将以下内容添加到Info.plist文件中
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>
    <key>LSApplicationQueriesSchemes</key>
     <array>
      <string>simplApp</string>
     </array>
  • 在您的AppDelegate中添加以下行
//Objective-C    
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication     annotation: (id)annotation
    { if ([[GSCallBackHandler sharedInstance] canHandleURL:url]) {
      return [[GSCallBackHandler sharedInstance] application:application openURL:url sourceApplication:sourceApplication      annotation:annotation] ;
    }

  return YES;
   }
//Swift
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
  if GSCallBackHandler.sharedInstance.canHandleURL(url) {
    return GSCallBackHandler.sharedInstance.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
  }

  return true
}
  • 开发者可以像下面这样切换到沙盒或生产环境
//Objective-C
[GSManager enableSandBoxEnvironment:YES]
//Swift
GSManager.enableSandBoxEnvironment(true)
  • 转到目标 -> 构建阶段 -> 点击"+"按钮添加新的运行脚本阶段,并添加以下脚本
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

这是为了绕过App Store发布前的bug,该bug要求在提交到App Store之前,iOS框架二进制文件必须从模拟器切片中移除。有一个bug报告: Xcode 6.1.1 & 6.2:包含模拟器切片的iOS框架不能提交到App Store以及Realm#1163和Carthage#188上的长期讨论。

如何使用

  • 导入框架
//Objective-C
#import <GetSimpl/GetSimpl.h>
//Swift
import GetSimpl
  • 使用您的商户ID初始化SDK,通常在您应用完成启动选项的方法中
//Objective-C
[GSManager initializeWithMerchantID@:@"Your merchant id"];
//Swift
GSManager.initializeWithMerchantID("Your merchant id")
  • 检查用户是否预先批准
//Objective-C
GSUser *user = [[GSUser alloc] initWithPhoneNumber:@"user mobile number" email:@"user email"];
[[GSManager sharedManager] checkApprovalForUser:user onCompletion:^(BOOL approved, BOOL isFirstTransactionOfUser,  NSString *buttonText ,NSError *error) {
 }]
//Swift
let user : GSUser = GSUser(phoneNumber :"user mobile number" email:@"user email")
GSManager.sharedManager.checkApprovalForUser(user){(approved:Bool,isFirstTransactionOfUser:Bool,buttonText : String?,error:NSError?)
}
  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按钮。

  • 实时批准:对于一些更愿意在传输数据之前不共享数据,但愿意在交易前通过共享数据实时批准用户的商户,可以使用以下批准调用:
//Objective-C
GSUser *user = [[GSUser alloc] initWithHashedPhoneNumber:@"hashed value of user phone number"];
user.extraParams = @{@"wallet_balance_in_paise" : @30000,@"transaction_amount_in_paise" : @20000};
[[GSManager sharedManager] checkApprovalForUser:user onCompletion:^(BOOL approved, BOOL isFirstTransactionOfUser,  NSString *buttonText ,NSError *error) {
 }]
//Swift
 let user = GSUser(hashedPhoneNumber: "hashed value of user phone number")
 user.extraParams = ["wallet_balance_in_paise" : 30000,"transaction_amount_in_paise" : 20000]
 GSManager.sharedManager.checkApprovalForUser(user){(approved:Bool,isFirstTransactionOfUser:Bool,buttonText : String?,error:NSError?)
}
extraParams ->  Extra properties of GSUser to be set as Key-Value pairs.Example of some keys are transaction_amount_in_paise, wallet_balance_in_paise,failed_transaction_bank_name,user_location,theatre_location,member_since, signed_in , etc.
This property has been provided so that merchants can provide additional parameters for real-time approval without upgrading the SDK.

如果商户使用hashedPhoneNumber进行预批准检查,则上述键将用于对用户提供实时批准,前提是商户在服务器端启用了实时配置。

  • 对于Simpl按钮,商户可以使用SDK提供的GSButton类,该类可以通过以下属性进行自定义
//Objective-C

/// Button background color. Defaults to Simpl branding color
@property (nonatomic, strong) UIColor *buttonColor;

/// Button border color. Defaults to Black Color with 10% alpha
@property (nonatomic, strong) UIColor *buttonBorderColor;

/// Title text of button. Defaults to "Buy Now, Pay Later"
@property (nonatomic, copy) NSString *titleText;

/// Title Color of Button. Defaults to White color
@property (nonatomic, strong) UIColor *titleColor;

/// Font of button
@property (nonatomic, strong) UIFont *titleFont;

/// Text color of "Powered by Simpl" text. Defaults to R94 G107 B125 A1
@property (nonatomic, strong) UIColor *poweredByTextColor;

/// Separator line color. Defaults to Black Color with 8% alpha
@property (nonatomic, strong) UIColor *separatorColor;

  • 单击“简化”按钮,将调用以下方法以开始交易。这将为用户打开一个用于输入的OTP视图。在完成块中,将返回 transaction_token。
//Objective-C
   GSUser *user = [[GSUser alloc] initWithPhoneNumber:@"user mobile number" email:@"user email"];
   GSTransaction *transaction = [[GSTransaction alloc] initWithUser:user amountInPaise:500];
[ [GSManager sharedManager]  authorizeTransaction:transaction onCompletion:^(NSDictionary * jsonResponse, NSError *  error) {
  }];
//Swift
let user : GSUser = GSUser(phoneNumber :"user mobile number" email :@"user email")
let transaction = GSTransaction(user: user, amountInPaise: 500)
GSManager.sharedManager.authorizeTransaction(transaction) { (jsonResponse : NSDictionary?, error:NSError?) -> Void in
}

在调用 authorizeTransaction 之前,必须设置 GSUser 的电话号码。一旦您获得 transaction_token,就可以将它传递到您的服务器,服务器随后可以将交易详情传递给 Simpl。