PaylevenMPosSdk 1.0

PaylevenMPosSdk 1.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2015年5月

Johannes Rupieper 维护。



  • Johannes Rupieper

payleven mPOS SDK

本项目提供了一个 iOS API,用于与 payleven Chip & PIN 卡读卡器通信,以接受借记卡和信用卡支付。了解更多关于 Chip & PIN 卡读卡器和支付选项的信息,请访问 payleven 的区域 网站

先决条件

  1. payleven 进行注册,以便获取个人商户凭据和卡读卡器。
  2. 为了获得 API 密钥,请通过发送电子邮件向我们联系 [email protected]

安装

手动设置
  1. PaylevenSDK.frameworkAdyenToolkit.frameworkAdyenToolkit.bundle 拖入您的 Xcode 项目中。

  2. 打开您的目标项目的 构建阶段,并将以下框架添加到 链接二进制与库 部分

    CoreData.framework  
    CoreLocation.framework
    ExternalAccessory.framework
    SystemConfiguration.framework
    libsqlite3.0.dylib
    
  3. 打开您的目标项目的 构建设置,并将 -ObjC 标志添加到其他链接器标志。

  4. 打开 Info.plist 并添加以下条目

    • CFBundleDisplayName 使用您的应用程序的显示名称。
    • UISupportedExternalAccessoryProtocols 使用只有一个值的数组 com.adyen.bt1
    • 对于 iOS 8:请使用 NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription,对于 iOS 7:请使用 NSLocationUsageDescription 并提供用户的位置使用描述信息。
  5. 在您的文件中导入 PaylevenSDK

    #import <PaylevenSDK/PaylevenSDK.h>
    

蓝牙配对

在进行集成和测试之前,请确保您已在 iOS 设备的蓝牙设置中配对了卡读卡器。

  1. 确保设备已充电并已开启。
  2. 按卡读卡器的“0”键 5 秒,并确保卡读卡器已进入配对模式(屏幕上将会有相应的标志)。
  3. 转到您的 iOS 设备的蓝牙设置并打开蓝牙。
  4. 选择已发现的 payleven 卡读卡器,并按两台设备上的说明完成配对过程。

入门

认证您的应用程序

使用从payleven获得的应用编程接口(API)密钥结合您的payleven商家账户来认证您的应用程序。提示:查看我们的示例演示,了解如何轻松地使用KVO观察登录状态。

 PLVPayleven * payleven = [[PLVPayleven alloc] init];
 [payleven loginWithUsername:@"aUsernameString"
                    password:@"aPasswordString"
                      APIKey:@"anApiKey"
           completionHandler:^(NSError *error) {

        if (error == nil) {
            // Congrats, you're Logged In
        } else {
            // Error Handling
        }
    }];
选择卡读卡器

创建一个PLVPayleven实例后,您需要为未来的付款选择卡读卡器。

 //You probably want to visualize the devices in a UITableView
 NSArray * pairedDevices = self.payleven.devices;

 //Get the selected device from the list
  PLVDevice *device = self.sortedDevices[indexPath.row];
  NSString * deviceName = device.name;
为付款准备卡读卡器

为即将进行的付款准备所选设备。

 [device prepareWithCompletionHandler:^(NSError *error) {
        if (device.isReady) {
            //Device is Ready, now let's do some Payment
        } else {
            // Error Handling
        }
    }];
启动付款

初始化实际的付款请求。出于安全考虑,您必须在PaymentReuest中提供用户的当前位置。

 //Here we are using an arbitrary location. In your app you must provide the user's current location
 CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(52.5243700, 13.4105300);

 NSLocale* locale = [NSLocale currentLocale];
 NSDecimalNumber* amount = [NSDecimalNumber decimalNumberWithString:@"1.00" locale:locale];

 PLVPaymentRequest* request = [[PLVPaymentRequest alloc] initWithIdentifier:@"anArbitraryUniqueIdentifier"
                                                                     amount:amount
                                                                   currency:@"EUR"
                                                                 coordinate:coordinate];

 //Hint: the corresponding delegate is PLVPaymentTaskDelegate                                                                
 self.paymentTask = [self.payleven paymentTaskWithRequest:request device:self.device delegate:self]
 if (self.paymentTask == nil) {
    //Could not create Payment  
 } else {
    [self.paymentTask start];
 }
处理付款

实现PLVPaymentTaskDelegate的方法以响应付款事件,如付款人的签名请求、最终批准或任何错误。

 - (void)paymentTask:(PLVPaymentTask *)paymentTask
        needsSignatureWithCompletionHandler:(void (^)(BOOL, CGImageRef))completionHandler {

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *navigationController
        = [storyboard instantiateViewControllerWithIdentifier:@"SignatureConfirmationNavigationController"];
    SignatureConfirmationViewController *signatureConfirmationViewController
        = (SignatureConfirmationViewController *)navigationController.topViewController;


    //Get Payer's signature and return using completionBlock (See our Sample App for full implementation)
    UIImage * signature = ...
    completionHandler(true, signature.CGImage);

 }

 - (void)paymentTaskDidFinish:(PLVPaymentTask *)paymentTask { 

    self.receiptGenerator = paymentTask.result.receiptGenerator;
    CGFloat scale = [UIScreen mainScreen].scale;
    [self.receiptGenerator generateReceiptWithWidth:(384.0 * scale)
                                           fontSize:(16.0 * scale)
                                        lineSpacing:(8.0 * scale)
                                            padding:(20.0 * scale)
                                  completionHandler:
     ^(CGImageRef receipt) {
         CGFloat scale = [UIScreen mainScreen].scale;
         UIImage *image = [UIImage imageWithCGImage:receipt scale:scale orientation:UIImageOrientationUp];
         self.receiptGenerator = nil;
     }];

    self.paymentTask = nil;
 }

 - (void)paymentTask:(PLVPaymentTask *)paymentTask didFailWithError:(NSError *)error {
    //Error handling
    self.paymentTask = nil;
 }

文档

API参考