本项目提供了一个 iOS API,用于与 payleven Chip & PIN 卡读卡器通信,以接受借记卡和信用卡支付。了解更多关于 Chip & PIN 卡读卡器和支付选项的信息,请访问 payleven 的区域 网站。
将 PaylevenSDK.framework、AdyenToolkit.framework 和 AdyenToolkit.bundle 拖入您的 Xcode 项目中。
打开您的目标项目的 构建阶段,并将以下框架添加到 链接二进制与库 部分
CoreData.framework
CoreLocation.framework
ExternalAccessory.framework
SystemConfiguration.framework
libsqlite3.0.dylib
打开您的目标项目的 构建设置,并将 -ObjC
标志添加到其他链接器标志。
打开 Info.plist 并添加以下条目
CFBundleDisplayName
使用您的应用程序的显示名称。UISupportedExternalAccessoryProtocols
使用只有一个值的数组 com.adyen.bt1
。NSLocationWhenInUseUsageDescription
或 NSLocationAlwaysUsageDescription
,对于 iOS 7:请使用 NSLocationUsageDescription
并提供用户的位置使用描述信息。在您的文件中导入 PaylevenSDK
#import <PaylevenSDK/PaylevenSDK.h>
在进行集成和测试之前,请确保您已在 iOS 设备的蓝牙设置中配对了卡读卡器。
使用从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;
}