CyberSource iOS SDK
此 SDK 提供简单的功能,可以将敏感信用卡数据直接发送到 CyberSource,并返回一个安全的支付令牌,可以传递到您的移动后端进行标准 CyberSource 处理,而无需承担信用卡数据触达服务器的负担。使用这个安全的支付令牌,您的服务器可以创建 CyberSource 订阅、长期令牌或支付。
注意:此 SDK 不适用于 ApplePay 交易,而是作为 Apple Passkit SDK 的补充。来自此 SDK 和 Apple Passkit SDK 的支付数据块可以像对待 CyberSource 支付处理一样处理。
SDK 安装
CocoaPods
pod 'cybersource-ios-sdk'
手动安装
将 InAppSDK.framework
添加到应用程序中。选择目标,在“嵌入的二进制文件”中,按加号 (+) 并选择框架。
一旦添加,请确保在“构建设置”标签中,“搜索路径”部分正确添加了这些框架的路径。
## SDK 使用在包含框架和路径之后,现在尝试在应用程序中包含以下框架头文件。
#import <InAppSDK/InAppSDK.h>
-(void) performPaymentDataEncryption
{
BOOL result = NO;
//Initialize the InAppSDK for CYBS Gateway Environtment.
[InAppSDKSettings sharedInstance].inAppSDKEnvironment = INAPPSDK_ENV_TEST;
//Initialize the transaction object which collects all the required information for the encrypt service.
//Refer: InAppSDKTransactionObject.h
InAppSDKTransactionObject * transactionObject = [[InAppSDKTransactionObject alloc] init];
//Set First Name, Last Name and Postal Code. These are optional Values, not mandatory.
//Refer: InAppSDKAddress.h
transactionObject.billTo = [self getBillToData];
//Get and Set the Merchant specific credentials [merchantID, Signature, merchant Reference code etc.]
//Refer: InAppSDKMerchant.h
transactionObject.merchant = [self getMerchantData];
//Get and Set the Card specific details[ cardNumber, expirationMonth, expirationYear and cvNumber.]
//Refer: InAppSDKCardData.h
transactionObject.cardData = [self getTestCardData];
//Initialize the InAppSDK Gateway and call performPaymentDataEncryption and implement the Delegate.
InAppSDKGateway * gateway = [InAppSDKGateway sharedInstance];
result = [gatway performPaymentDataEncryption:transactionObject withDelegate:self];
if (result)
{
NSLog(@"Request is Accepted. Expect the response in the delegate method.");
}
else
{
NSLog(@"Request is NOT Accepted. Verify the input values if any one is invalid.");
}
}
//Delegate. Refer InAppSDKGatewayProtocol.h
- (void) encryptPaymentDataServiceFinishedWithGatewayResponse:(InAppSDKGatewayResponse *)paramResponseData withError:(InAppSDKError *)paramError
{
if(paramError != nil || paramResponseData != nil)
{
NSMutableString* statusMsg = [NSMutableString new];
if (paramResponseData)
{
[statusMsg appendString:@"\nEncrypt Payment Data Service Response:"];
[statusMsg appendFormat:@"\nAccepted: %@", paramResponseData.isAccepted ? @"Yes" : @"No"];
[statusMsg appendFormat:@"\nRequestID %@", paramResponseData.requestId];
[statusMsg appendFormat:@"\nResultCode %@", paramResponseData.resultCode];
[statusMsg appendFormat:@"\nEncrypted Payment Data:%@", paramResponseData.encryptedPayment.data];
}
if (paramError)
{
[statusMsg appendFormat:@"\nError: %@", paramError.localizedDescription];
}
NSLog(@"%@", statusMsg);
}
}
-(InAppSDKAddress *) getBillToData
{
InAppSDKAddress * billToInfo = [[InAppSDKAddress alloc] init];
billToInfo.firstName = @"TestFirstName";
billToInfo.lastName = @"TestLastName";
billToInfo.postalCode = @"98004";
return billToInfo;
}
-(InAppSDKCardData*) getTestCardData
{
InAppSDKCardData* testCardData = [[InAppSDKCardData alloc] init];
testCardData.accountNumber = @"4111111111111111";
testCardData.expirationMonth = @"12";
testCardData.expirationYear = @"2018";
[testCardData setCvNumber:@"123"];
return testCardData;
}
-(InAppSDKMerchant*) getMerchantData
{
InAppSDKMerchant *merchantData = [[InAppSDKMerchant alloc] init];
merchantData.userName = kInAppTestUserName;
merchantData.merchantID = kInAppTestMerchantID;
merchantData.merchantReferenceCode = kInAppTestMerchantReferenceNumber;
//-------WARNING!----------------
// This part of the code that generates the Signature is present here only to show as a sample.
// Signature generation must be done and obtained from the Merchant Server.
InAppSDKSignatureGenerator * signatureGenerator = [[InAppSDKSignatureGenerator alloc] init];
NSString * signature = [signatureGenerator generateSignatureWithMerchantId:kInAppTestMerchantID
transactionSecretKey:kInAppTestTransactionSecretKey
merchantReferenceCode:kInAppTestMerchantReferenceNumber ];
NSLog(@"Signature:%@", signature);
merchantData.passwordDigest = signature;
return merchantData;
}
示例应用程序
我们有一个示例应用程序,演示了SDK的使用
https://github.com/CyberSource/cybersource-ios-samples
使用支付blob
一旦从我们的SDK中获得了安全的支付blob,您可以将其上传到您的移动后端/支付服务器(而不会承担任何额外的PCI负担),并执行标准的CyberSource API调用。例如,授权该卡片
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>test_paymentech_001</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-1.0#PasswordText">POgqicGXdrqafap/7WzT/KcYVzuN/aW4u1cuRKawBvOg==</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<nvpRequest xmlns="urn:schemas-cybersource-com:transaction-data-1.121">
ccAuthService_run=true
merchantID=test_paymentech_001
merchantReferenceCode=23AEE8CB6B62EE2AF07
encryptedPayment_data=eyJkYXRhIjoiN2kxTUxjWEIxRXZoMjk2emRJdnFyY1hZXC93SG9zRE9jbXdVRE1PRG5tdk9xWXJZWXlpTXhmRzc0bTRWbndTblwvN1FEdjlYUm9kZHNxalc4aXpoTVA4cXpDOG5HVkhMa3ZES2ZVYVNqWnB3WURKS2JaYk5JNklVcE1QUjlPWmJ2NFJ5VE5tbUprcmlVU25JbFwvbVRobWprbkh1eXpwc3FFRzdVR21wcXNkOHczaG50ZStvaUpSU2pBbmtraTI1T2hmUFlqTU9CUE9BaHNFMUsxM0Npc3dNWTA4dEN5K1V3VEhuakY5MThyTFVkXC9jMnpKTW9BOEFjN042SHFPQklWa2plUVwvd25rOGkyeGNcL3lubE51bTlMMlR5RGRnRE42SHNYWjNRb3V6Z053cTZyTGFSYjU5WGpMSlVXUmRDcU5namtFTjZlUkE0Mk94NElubDlQc0RKblRpbzZ4SDVcLyIsImhlYWRlciI6eyJhcHBsaWNhdGlvbkRhdGEiOiI0Nzc1Njk2NDNEMzczMDM4MzI2MzM5MzEzNjJENjI2MjY0NjMyRDM0MzY2NTY1MkQzODM0MzEzMDJENjM2NDM1MzEzNDMxMzQzNTMzNjUzNjM1M0I0NDYxNzQ2NTU0Njk2RDY1M0QzMjMwMzEzNTJEMzEzMjJEMzEzNDU0MzIzMDNBMzMzMTNBMzAzNTJFMzEzMjMzMzAzOTMwMzI1QSIsImVwaGVtZXJhbFB1YmxpY0tleSI6Ik1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRU80V2prRzFLYXlpbmhlRGY5QXFtRVJCeHRxMHdiaFBmS25qcUNCZ0w4RWw4NU45c3JBWVdhaEE1d29iaHFTQ0VQazc5Q0xKNGhRVXU1bENIem43ZVdBPT0iLCJwdWJsaWNLZXlIYXNoIjoieXRLSjgwc3JjWXppQnVwNzRcL0R5K3RTV1FQSENwXC9ZbkFabGhcL3lXOFk3ND0iLCJ0cmFuc2FjdGlvbklkIjoiNDUwMTI1MDYyMDA3NTAwMDAwMTUxOSJ9LCJzaWduYXR1cmVBbGdJbmZvIjoiU0hBMjU2Iiwic2lnbmF0dXJlIjoiWitjbWg4UXNzNUdQMzUrOEEzTkZOcUNNRThFbVBqb0xiKzRqUWpIVDdGMD0iLCJ2ZXJzaW9uIjoiMS4xLjEuMiJ9
paymentSolution=004
billTo_firstName=Brian
billTo_lastName=McManus
billTo_city=Bellevue
billTo_country=US
[email protected]
billTo_state=WA
billTo_street1=213 yiui St
billTo_postalCode=98103
purchaseTotals_currency=USD
purchaseTotals_grandTotalAmount=200.23
</nvpRequest>
</soapenv:Body>
</soapenv:Envelope>
注意:您还可以通过调用ics_create_subscription来创建一个永久的卡存储支付令牌,只需将卡片数据字段替换为加密的Payment_data字段,并别忘了将paymentSolution设置为004。
Apple In-App Purchase API
请记住,您必须使用Apple的In-App Purchase API来销售虚拟商品,例如您的应用的高级内容或数字内容的订阅。具体来说,Apple的开发者条款要求,必须使用In-App Purchase API来处理数字的“内容、功能或服务”,例如高级功能或积分。有关详细信息,请参阅https://developer.apple.com/app-store/review/guidelines/。