PayDirectSMSCharging 1.0.2

PayDirectSMSCharging 1.0.2

许可 MIT
发布最后发布2016年5月

DuyKienNgo 维护。



  • Homedirect

其他语言英文

介绍

PayDirectSMSCharging 提供将 sms 支付集成到您的应用程序中,通过 9029 号码的最简单方式。

PaySMSCharging iOS SDK 支持 iOS 6.0 及以上版本

需求

开发环境

PaySMS 版本 最低 iOS 目标版本 注意
1.0.0 6.0 需要 Xcode 6.1。支持 armv7, armv7s 和 arm64 架构(+ i386 用于模拟器)

兼容性

PayDirectSMSCharging iOS SDK 支持所有 iOS 6.0 及以上版本。支持 armv7, armv7s 和 arm64 架构(+ i386 用于模拟器)。

Xcode

我们使用 Xcode 7.3 编写项目示例和 SDK。如果使用旧版本 Xcode 打开可能会遇到一些错误。这就是我们建议您使用最新版(non-beta)的原因。

从项目示例开始

您需要将此仓库克隆或下载到您的计算机上。

运行项目。应用程序描述了 PaySMS 的功能和集成方式。

与 PayDirectSMSCharging 集成的 6 个步骤

1. 注册账户(创建 MO Code)

您需要做的第一件事是为 PaySMSCharging 注册客户账户。请通过 Email 或 Skype (kythuat_paydirect) 联系。在创建账户后,您可以访问 PayDirectSMSCharging 控制台,并将 PayDirectSMSCharging 集成到您的应用程序中。

2. 下载 SDK

将PayDirectSMSCharging加载到项目Xcode的方式有很多。您可以使用CocoaPod或手动下载并添加框架和相关库到项目中。

Cocoapod(即将推出)

CocoaPod是最快的方法来在iOS应用上加载和运行PayDirectSMSCharging。只需在Podfile中添加以下行,然后运行pod installpod update命令。

pod 'PayDirectSMSCharging'

加载PayDirectSMSCharging

您可以直接从repo下载iOS SDK。解压缩PayDirectSMSCharging,然后将PayDirectSMSCharging及其框架拖入您的项目。

3. 集成SDK

Frameworks & Dependencies

PayDirectSMSCharging SDK依赖于一些其他框架。您需要将它们添加到自己的项目中。具体需要添加以下框架

Framework
SystemConfiguration.framework
CoreMobileServices.framework
CoreTelephony.framework

4. 开始编码

4.1. 导入SDK

SDK通过PayDirectSMSCharging.h类进行导入。

#import <PayDirectSMSCharging/PayDirectSMSCharging.h>

4.2. 初始化PDSMSChargingClient

当您需要使用PaySMS SDK时,您需要初始化一个PDSMSChargingClient。

    NSString* moCode = @"YOUR_APP_MO_CODE";
    NSString* accountName = @"USER_ACCOUNT_NAME_OR_ID";
    paySMSChargingClient = [[PDSMSChargingClient alloc] initWithMOCode:moCode
                                            accountName:accountName];
    paySMSChargingClient.dataSource = self;

应如何设置accountName的值?

  • 如果您的游戏/应用有用户,accountName的值应与您的系统中用户ID相同。
  • 如果您的游戏/应用没有用户,accountName的值应与设备ID对应。
  • accountName仅包含a-z、A-Z和0-9字符。

4.3. 配置/选择电信服务代码

  • PayDirectSMSCharging允许使用多个不同的短信代码,如VTC(适用于所有Mobifone、Vinaphone、Viettel网络),BX(适用于Mobifone和Vinaphone网络),QK(适用于Viettel网络)。默认情况下,我们选择VTC作为短信服务代码。但是,您可以通过在PDSMSChargingClientDataSource中定义的- (NSString * _Nullable)partnerCodeForAmount: (PDSMSAmount * _Nonnull)amount方法选择适用于您的游戏/应用的代码。
- (NSString * _Nullable)partnerCodeForAmount:(PDSMSAmount * _Nonnull)amount {
    // You can custom telecom service code here
    // Ex: For Mobifone, there are VTC and BX codes. The default value is VTC,
    // but you can choose the BX code by "return" BX value here.
    if (amount.provider == kPaySMSProviderMobifone) {
        return @"BX";
    }
    // It is also you can choose BX as partner Code for Vinaphone
    else if (amount.provider == kPaySMSProviderVinaphone) {
        // For BX, there is no amount with value == 100K, so,
        // if the amount == 100K, and you choose "BX", it will raise the Assertion
        return @"BX";
    } else if (amount.provider == kPaySMSProviderViettel) {
        // For BX, there is no amount with value == 100K, so,
        // if the amount == 100K, and you choose "BX", it will raise the Assertion
        return @"QK";
    }

    // When this function return null or the listener is nil/NULL,
    // it will using  QK , BX as default for Viettel and Vinaphone/Mobifone partner code
    return nil;
}

4.4. 创建短信代码并发送短信到头号9029(通过头号9029支付)

4.1. 使用PayDirectSMSCharging SDK中提供的UI

使用这种方法,用户可以选择运营商和充值面值(如图所示)进行充值交易。

SMS Charging by UI

要进行支付,您需要

  • 创建一个PaySMSController
    // the paySMSChargingClient you already inited above 
    PaySMSController* paySMSController = [[PaySMSController alloc]  initWithSMSClient:paySMSChargingClient];
    paySMSController.delegate = self;
    // implement PaySMSControllerDelegate for custom the telecom and par value
    [self presentViewController:paySMSController
                       animated:YES
                     completion:nil];                     
  • 要配置/选择运营商或充值面值,您可以在PDSMSChargingControllerDelegate中实现所需的函数。

选择运营商:您需要实现一个名为 (NSArray*)supportedProviders: (PaySMSController * _Nonnull)viewController 的函数,它在 PaySMSControllerDelegate 中被描述,以便选择游戏/应用程序支持的运营商。以下示例允许用户只选择 Mobilfone 和 Vinaphone。只需不实现此函数或返回 nil/null 值,以便游戏/应用程序允许用户选择所有运营商。

/**
 *  This function for developer can set the list of telecom, that the game/app supported
 *  This function is optional, and if the function return null or an empty array list,
 *  the SDK will show all Providers
 *
 *  @param viewController The PaySMSController
 */
- (NSArray*)supportedProviders:(PaySMSController * _Nonnull)viewController {
    //this is an example when you want user choose Mobilfone or Vinaphone only
      NSArray* supportedProviders = @[@(kPaySMSProviderMobifone),
                                    @(kPaySMSProviderVinaphone)];
      return supportedProviders;
}

选择面额:您需要实现一个名为 availableFairValuesForProvider:inController: 的函数,它在 PDSMSChargingControllerDelegate 中被描述,以便选择游戏/应用程序支持的面额。以下示例允许用户只选择 1K、5K 和 100K 的面额。只需不实现此函数或返回 nil/null 值,以便游戏/应用程序允许用户选择所有支持的面额。

/**
 *  This function for developer can set the list of fair values for providers
 *  This function is optional, and if the function return null or an empty array list,
 *  the SDK still show all available fair values
 *
 *  @param viewController The PDVoucherUseCardViewController its delegate of fail
 *  @param result         The selected (and possibly newly created) tokenized payment information.
 */
- (NSArray*)availableFairValuesForProvider:(PDSMSProvider)provider
                              inController:(PDSMSChargingController * _Nonnull)viewController {

    // This is the way you want user to pick some par values only
    // An example with Viettel
    if (provider == kPDSMSProviderViettel) {
        return @[@(kPDSMSParValue1K),
                 @(kPDSMSParValue5K),
                 @(kPDSMSParValue10K)];
    }

    // return nil/NULL/Empty array, the SDK will allows user to choose all par values
    return nil;
}
  • 对于使用界面的方法,您无需编写代码让用户选择运营商或充值面额。为了捕获 SMS 充值过程中的事件,您需要实现以下一些函数

用户取消支付事件

/**
 *  Informs the delegate when the user has decided to cancel out of the Pay by SMS form.
 *
 *  @param viewController The PaySMSController view controller informing its delegate of failure or cancelation.
 */
- (void)userDidCancel:(PDSMSChargingController * _Nonnull)viewController {
    [viewController dismissViewControllerAnimated:YES
                                       completion:nil];

//    [viewController dismissViewControllerAnimated:YES
//                                       completion:^{
//                                           [self.alert cancelAlertWithTitle:nil
//                                                                    message:NSLocalizedString(@"User did cancel", @"User did cancel")
//                                                                cancelTitle:NSLocalizedString(@"OK", @"OK")
//                                                              cancelHandler:^{
//                                                              }];
//                                       }];
}

成功发送 SMS 事件

/**
 *  Informs the delegate when the SMS did send
 *
 *  @param viewController The PaySMSController view controller informing its delegate of failure or cancelation.
 */
- (void)smsDidSend:(PDSMSChargingController * _Nonnull)viewController {
    [self.alert cancelAlertWithTitle:nil
                             message:NSLocalizedString(@"The SMS did sent", @"The SMS did sent")
                         cancelTitle:NSLocalizedString(@"OK", @"OK")
                       cancelHandler:^{}];
}

无法发送 SMS 事件

/**
 *  Informs the delegate when the sms failed
 *
 *  @param viewController The PaySMSController view controller informing its delegate of failure.
 */
- (void)smsFailed:(PDSMSChargingController * _Nonnull)viewController {
    [self.alert cancelAlertWithTitle:nil
                             message:NSLocalizedString(@"Can not send SMS", @"Can not send SMS")
                         cancelTitle:NSLocalizedString(@"OK", @"OK")
                       cancelHandler:^{}];
}

4.2. 使用 PaySMSChargingClient 根据运营商参数(PDSMSProvider)和卡面值(PDSMSParValue)自动创建 SMS 语法

    // Init an amount to charge by PaySMS 
    PaySMSAmount* amount = [[PaySMSAmount alloc] init];
    // Set your telecom: Mobilfone/Vinaphone or Viettel. It should be the user's telecom.
    amount.provider = kPaySMSProviderMobifone;
    // The par value to charge by PaySMS: 1K, 2K, 3K, 4K, 5K, 10K, 15K, 20K, 30K, 40K, 50K, 100K
    amount.parValue = kPaySMSParValue1K;


    // Generate the SMS Syntax 
    NSString* smsSyntax = [paySMSChargingClient smsSyntax:amount];

    // In case the par value is not supported by telecom, the smsSyntax returned will be nil
    if (smsSyntax) {
        // It is an example for you can use 'smsSyntax', Alert to user 
        NSString * message = [NSString stringWithFormat:NSLocalizedString(@"The syntax is: %@. Do you want to send to the provider?", @"The syntax is: \"%@\". Do you want to send to the provider?"),smsSyntax];
        [self.alert alertWithTitle:nil
                           message:message
                            titles:@[NSLocalizedString(@"Yes", @"Yes"),
                                     NSLocalizedString(@"Cancel", @"Cancel")]
                          handlers:@[^{
            // And send SMS by using MFMessageComposeViewController
            if ([MFMessageComposeViewController canSendText]) {
                MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
                messageController.messageComposeDelegate = self;
                [messageController setRecipients:@[@"9029"]];
                [messageController setBody:smsSyntax];

                [self presentViewController:messageController
                                   animated:YES
                                 completion:nil];
            }
        }, ^ {

        }]];
    }

恭喜您,您已成功集成 PayDirectSMSCharging

支持

请就一般性问题与我们联系:这里

关于技术问题

如果您有技术问题,请与我们的技术团队联系:这里 联系时,请提供以下信息,这将帮助我们更快地支持您。