Skip to content

PayBy Payment Gateway integration SDK for apple iOS with In-app pay scenes

License

Notifications You must be signed in to change notification settings

PayBy/PayBy-inApp-iOS

Repository files navigation

PayBy-inApp-iOS

PayBy Payment Gateway integration SDK for iOS with In-app pay scenes

Term Definition

  • deviceId: Every device has its own unique deviceId. UAT environment [joint debugging] fixed: deviceId123
  • partnerId: Every merchant is assigned a partnerId while applying for the payment service
  • appId: Every app of a merchant is assigned an appId while applying for the payment service
  • token: It contains order information
  • sign: First, generate a singString by arranging deviceId、partnerId、appId、token order. The rules are as follows: String signString = "iapAppId="+appId+"&iapDeviceId=" +deviceId+"&iapPartnerId="+partnerId+"&token="+token; Second, sign the signString with privateKey, and the encryption rules can be seen in the demo. Note: For demo purposes, the sign is generated on the app client. For security, the sign should be generated by the server and then returned to the client.

Applicable version

Use Xcode 10 and above to use the new version of SLDPayByPayment SDK, iOS 10.0 and above

Installation

Installation with CocoaPods

[1] Build your project in XCode.

[2] To integrate SLDPayByPayment into your Xcode project using CocoaPods, specify it in your Podfile:

# This source must be added
source 'https://github.com/PayBy/CocoaPodsSpecs.git' 

pod 'PXRPPayByPayment'

Save and execute pod install, then open the project with a file with the suffix .xcworkspace. Note: If you are using SLDPayByPayment now, please replace it with PXRPPayByPayment, run pod install to install, and then the new SLDPayByPayment.framework will be integrated into you project. SLDPayByPayment pod doesn't been maintained any more.

[3] In Xcode, select your project settings, select the "TARGETS" column, and add "URL scheme" to the "URL Types" in the "Info" tab bar for your registered application "payby" + iapAppId (As shown). Image text

[4] In Xcode, select your project settings, select the "TARGETS" column, and change "Architectures" to "arm64" in the "Build Settings" tab (As shown). Image text

[5] In Xcode, select your project settings, select the "TARGETS" column, and change "Enable Bitcode" to "No" in the "Build Settings" tab (As shown). Image text

Usage

Initialize SDK (Required)

#import "AppDelegate.h"
#import <SLDPayByPayment/SLDPayByPayment.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [SLDPayByPaymentInterface setLogEnabled:YES];
    
//    [SLDPayByPaymentInterface setLanguage:SLDPayByPaymentLanguageEn];
//    [SLDPayByPaymentInterface setUserInterfaceStyle:SLDPayByPaymentUserInterfaceStyleDark];
//    SLDPayByPaymentConfig *config = [SLDPayByPaymentConfig defaultConfig];
//    config.paymentMethodMenuColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor redColor] darkColor:[UIColor greenColor]];
//    config.paymentMethodTextColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor whiteColor] darkColor:[UIColor blackColor]];
//    config.primaryColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor blueColor] darkColor:[UIColor blueColor]];
//    config.appPayUseQrCode = NO;
//    config.useDefaultResultPage = YES;
//    [SLDPayByPaymentInterface updateConfig:config];

    [SLDPayByPaymentInterface initWithAppId:{appId} partnerId:{partnerId} environment:SLDPayByPaymentEnvironmentDevelop];

    ...

    return YES;
}

@end

SLDPayByPaymentEnvironment Description:

  • SLDPayByPaymentEnvironmentDevelop: The environment for developing and testing.
  • SLDPayByPaymentEnvironmentUAT: The environment for customer debuging.
  • SLDPayByPaymentEnvironmentRelease: The environment for product online.

Call methods in your class (Objective-C)

NSString *sign = [NSString stringWithFormat:@"iapAppId=%@&iapDeviceId=%@&iapPartnerId=%@&token=%@", self.appIdTextField.text, self.deviceIdTextField.text, self.partnerIdTextField.text, self.tokenTextField.text];
[SLDPayByPaymentInterface paymentInViewController:self withToken:self.tokenTextField.text sign:[GPBRSA encryptString:sign privateKey:[GlobalDefines privateKey]] deviceId:self.deviceIdTextField.text resultCallback:^(NSString * _Nonnull result) {
    NSLog(@"resultCallback: %@", result);
    if ([SLDPayByPaymentConfig defaultConfig].useDefaultResultPage == NO) {
        [self showAlertWithMessage:result];
    }
}];

Call methods in your class (Swift)

let token = self.tokenTextField.text ?? ""
let deviceId = self.deviceIdTextField.text ?? ""
let sign = "iapAppId=\(self.appIdTextField.text ?? "")&iapDeviceId=\(deviceId)&iapPartnerId=\(self.partnerIdTextField.text ?? "")&token=\(token)"
SLDPayByPaymentInterface.payment(in: self, withToken: token, sign: GPBRSA.encryptString(sign, privateKey: GlobalDefines.privateKey()), deviceId: deviceId) { [weak self] result in
    print("resultCallback: \(result)")
    if SLDPayByPaymentConfig.default().useDefaultResultPage == false {
        self?.showAlert(with: result)
    }
}

Payment Result Code Description

  • SUCCESS: The payee has received the payment successfully, and the entire payment process for the order is completed.
  • FAIL: Payment failed.
  • PAYING: Processing. Wait for the payment process to complete and return the final payment result.
  • CANCEL: Cancel payment, the callback status received by the user after clicking the Close button.

1.x.x version migration 2.x.x version guide

[1] Add the following code to your project Podfile:

# This source must be added
source 'https://github.com/PayBy/CocoaPodsSpecs.git' 

pod 'PXRPPayByPayment'

[2] Please use SLDPayByPaymentInterface replace SDLPayByPaymentInterface

[3] Initialize SDK,use the following code

#import "AppDelegate.h"
#import <SLDPayByPayment/SLDPayByPayment.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [SLDPayByPaymentInterface setLogEnabled:YES];
    
//    [SLDPayByPaymentInterface setLanguage:SLDPayByPaymentLanguageEn];
//    [SLDPayByPaymentInterface setUserInterfaceStyle:SLDPayByPaymentUserInterfaceStyleDark];
//    SLDPayByPaymentConfig *config = [SLDPayByPaymentConfig defaultConfig];
//    config.paymentMethodMenuColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor redColor] darkColor:[UIColor greenColor]];
//    config.paymentMethodTextColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor whiteColor] darkColor:[UIColor blackColor]];
//    config.primaryColor = [SLDPayByPaymentColor colorWithLightColor:[UIColor blueColor] darkColor:[UIColor blueColor]];
//    config.appPayUseQrCode = NO;
//    config.useDefaultResultPage = YES;
//    [SLDPayByPaymentInterface updateConfig:config];

    [SLDPayByPaymentInterface initWithAppId:{appId} partnerId:{partnerId} environment:SLDPayByPaymentEnvironmentDevelop];

    ...

    return YES;
}

@end

replace the following code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Setting up the development environment
    [SDLPayByPaymentInterface paymentEnvironment:SDLPaymentEnvironmentTest]
    [SDLPayByPaymentInterface initInApp:appId partnerId:partnerId];
    return YES;
}

[4] Call methods in your class,use the following code

NSString *sign = [NSString stringWithFormat:@"iapAppId=%@&iapDeviceId=%@&iapPartnerId=%@&token=%@", self.appIdTextField.text, self.deviceIdTextField.text, self.partnerIdTextField.text, self.tokenTextField.text];
[SLDPayByPaymentInterface paymentInViewController:self withToken:self.tokenTextField.text sign:[GPBRSA encryptString:sign privateKey:[GlobalDefines privateKey]] deviceId:self.deviceIdTextField.text resultCallback:^(NSString * _Nonnull result) {
    NSLog(@"resultCallback: %@", result);
    if ([SLDPayByPaymentConfig defaultConfig].useDefaultResultPage == NO) {
        [self showAlertWithMessage:result];
    }
}];

replace the following code

[SDLPayByPaymentInterface payInAppWithViewContorller:self orderCallback:^(OrderSuccessCallback  _Nonnull orderSuccessCallback, OrderFailCallback  _Nonnull orderFailCallback) {
    //get order token
    NSString *token = [self getTokenMock];
    if (token && token.length > 0) {
        orderSuccessCallback(token,deviceId,sigin);
    }else{
        orderFailCallback();
    }
} success:^(id  _Nonnull result) {
    if([result isKindOfClass:[NSString class]]){
        [self alertView:result];
    }
} fail:^(NSError * _Nonnull error) {
    [self alertView:error.userInfo[@"errorInfo"]];
}];

About

PayBy Payment Gateway integration SDK for apple iOS with In-app pay scenes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •