Create Token
iOS
如欲了解最新版號 SDK 以及各版號之間的差異性,請參考 Github Release Page : TapPay iOS Github
此步驟將會把客戶的卡片轉為一個不敏感的字串稱之為 prime token
在您的 iOS 應用程式中取得該字串有 5 個步驟:
- 下載我們的 SDK 套件並將 TPDirect.framework 及 TPDirectResource 加入至您的專案中: TPDirect.framework
- 使用 TPDSetup 設定環境
- 在 Main.storyboard 中新增 UIView
- 透過 TPDForm 初始化 TPDCard
- 利用 TPDCard 取得 prime 字串
TPDSetup
+ (instancetype _Nonnull)setWithAppId:(int)appId
withAppKey:(NSString *_Nonnull)appKey
withServerType:(TPDServerType)serverType;
class func setWithAppId(_ appId: Int32, withAppKey appKey: String, with serverType: TPDServerType) -> Self
名稱 | 類別 | 內容 |
---|---|---|
appID | int | 請參考 appid |
appKey | String | 請參考 appkey |
serverType | TPDServerType | 使用的伺服器種類 測試時請使用 Sandbox 環境 (TPDServerType.Sandbox) 實體上線後請切換至 Production 環境 (TPDServerType.Production) |
在您的 Appdelegate 中 import TPDirect,並在 didFinishLaunchingWithOptions 中使用 TPDSetup 來設定環境
#import <TPDirect/TPDirect.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[TPDSetup setWithAppId:AppId withAppKey:@"AppKey" withServerType:TPDServer_SandBox];
return YES;
}
import TPDirect
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
TPDSetup.setWithAppId(AppId, withAppKey: AppKey, with: TPDServerType.sandBox)
return true
}
UIView
在 Main.storyboard 中新增 UIView,並將 UIButton 設定為 AutoLayout (UIView 建議寬高大小至少為 (270,70))
在 ViewController 設定 UIView 的 @IBOutlet 以及 UIButton 的 @IBOutlet 跟 @IBAction
TPDForm
+ (instancetype)setupWithContainer:(UIView *)view;
+ (instancetype _Nonnull)setup:(TPDForm * _Nonnull)tpdForm;
- (instancetype _Nonnull)onFormUpdated:(void(^_Nonnull)(TPDStatus *_Nonnull status))callback;
class func setup(withContainer view: UIView) -> Self
class func setup(_ tpdForm: TPDForm) -> Self
func onFormUpdated(_ callback: @escaping (_ status: TPDStatus) -> Void) -> Self
TPDForm 為用來取得消費者卡片資訊的欄位
您必須先用您客製化的 view 來設定
在將設定完成後的 TPDForm 傳至 TPDCard 來初始化
您可利用 onFormUpdated() 來得知目前卡片資訊的輸入狀態
並用回傳的 TPDStatus 來做判斷及處理
最後再用 isCanGetPrime() 來檢查參數是否都正確
在測試環境時,請一律使用測試卡號(4242424242424242, 01/23, 123)
#import "TapPayViewController.h"
#import <TPDirect/TPDirect.h>
@interface TapPayViewController ()
@property (weak, nonatomic) IBOutlet UIView *cardView;
@property (weak, nonatomic) IBOutlet UIButton *payButton;
@property (strong, nonatomic) TPDForm *tpdForm;
@property (strong, nonatomic) TPDCard *tpdCard;
@end
@implementation TapPayViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 1. Setup TPDForm With Your Customized CardView(260, 70)
self.tpdForm = [TPDForm setupWithContainer:self.cardView];
self.tpdCard = [TPDCard setup:(self.tpdForm)];
[self.tpdForm setErrorColor:[self colorWithRGB:@"FF5858" withAlpha:1]];
// 2. Use callback Get Status
[self.tpdForm onFormUpdated:^(TPDStatus * _Nonnull status) {
[self.payButton setEnabled:[status isCanGetPrime]];
self.payButton.alpha = [status isCanGetPrime] ? 1.0 : 0.25;
}];
[self.payButton setEnabled:NO];
self.payButton.alpha = 0.25;
}
import UIKit
import TPDirect
class TapPayViewController: UIViewController {
//MARK: - @IBOutlet
@IBOutlet weak var cardView: UIView!
@IBOutlet weak var payButton: UIButton!
var tpdForm : TPDForm!
var tpdCard : TPDCard!
override func viewDidLoad() {
super.viewDidLoad()
// 1. Setup TPDForm With Your Customized CardView(260, 70)
self.tpdForm = TPDForm.setup(withContainer: cardView)
self.tpdCard = TPDCard.setup(self.tpdForm)
self.tpdForm.setErrorColor(UIColor.red)
// 2. Use callback Get Status
self.tpdForm.onFormUpdated { (status) in
self.payButton.isEnabled = status.isCanGetPrime()
self.payButton.alpha = (status.isCanGetPrime()) ? 1.0 : 0.25
}
self.payButton.isEnabled = false
self.payButton.alpha = 0.25
}
}
setIsUsedCcv
- (void)setIsUsedCcv:(BOOL)isUsedCcv;
func setIsUsedCcv(_ isUsedCcv: Bool)
使用此方法設定是否要顯示 ccv 欄位
Get Prime
若為 AE 卡且 3DS2.0 交易,後 3 碼必須帶入,否則會造成交易失敗
- (instancetype _Nonnull)onSuccessCallback:(void(^ _Nonnull)(NSString *_Nullable prime, TPDCardInfo *_Nullable cardInfo, NSString * cardIdentifier, NSDictionary *_Nonnull merchantReferenceInfo))callback;
- (instancetype _Nonnull)onFailureCallback:(void(^ _Nonnull)(NSInteger status, NSString *_Nonnull message))callback;
- (void)getPrime;
func onSuccessCallback(_ callback: @escaping (_ prime: String?, _ cardInfo: TPDCardInfo?, _ cardIdentifier: String?, _ merchantReferenceInfo: [AnyHashable:Any]) -> Void) -> Self
func onFailureCallback(_ callback: @escaping (_ status: Int, _ message: String) -> Void) -> Self
func getPrime()
將 TPDCard 設定好成功及失敗 callback 後,即可呼叫 getPrime 來取得 prime 字串
之後再將它傳至您的伺服器,並呼叫 Pay by Prime API 來完成付款
- (IBAction)doneAction:(id)sender {
// Example Card
// Number : 4242 4242 4242 4242
// DueMonth : 01
// DueYear : 23
// CCV : 123
[[[tpdCard onSuccessCallback:^(NSString * _Nullable prime, TPDCardInfo * _Nullable cardInfo, NSString * cardIdentifier, NSDictionary * merchantReferenceInfo) {
NSLog(@"Prime : %@, LastFour : %@", prime, cardInfo.lastFour);
NSLog(@"Bincode : %@, Issuer : %@, cardType : %lu, funding : %lu ,country : %@ , countryCode : %@ , level : %@", cardInfo.bincode, cardInfo.issuer, cardInfo.cardType, cardInfo.funding , cardInfo.country,cardInfo.countryCode,cardInfo.level);
[self showResult:[NSString stringWithFormat:@"Prime : %@, LastFour : %@, Bincode : %@, Issuer : %@, cardType : %lu, funding : %lu ,country : %@ , countryCode : %@ , level : %@" , prime, cardInfo.lastFour, cardInfo.bincode, cardInfo.issuer, cardInfo.cardType, cardInfo.funding, cardInfo.country,cardInfo.countryCode,cardInfo.level]];
}] onFailureCallback:^(NSInteger status, NSString * _Nonnull message) {
//
NSLog(@"Status : %ld, Message : %@", status, message);
[self showResult:[NSString stringWithFormat:@"Status : %ld, Message : %@", status, message]];
}] getPrime];
}
@IBAction func doneAction(_ sender: Any) {
// Example Card
// Number : 4242 4242 4242 4242
// DueMonth : 01
// DueYear : 23
// CCV : 123
tpdCard.onSuccessCallback { (prime, cardInfo, cardIdentifier, merchantReferenceInfo) in
print("Prime : \(prime!), LastFour : \(cardInfo!.lastFour!)")
print("Bincode : \(cardInfo!.bincode!), Issuer : \(cardInfo!.issuer!), cardType : \(cardInfo!.cardType), funding : \(cardInfo!.funding) ,country : \(cardInfo!.country!) , countryCode : \(cardInfo!.countryCode!) , level : \(cardInfo!.level!)")
}.onFailureCallback { (status, message) in
print("status : \(status) , Message : \(message)")
}.getPrime()
}
Response
名稱 | 內容 | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
status | 錯誤代碼,0 為成功 | |||||||||||||||||||||||||||||||||
message | 錯誤訊息 | |||||||||||||||||||||||||||||||||
prime | prime 字串,於 Pay by Prime 交易時使用 | |||||||||||||||||||||||||||||||||
cardInfo | 卡片資訊,將會回傳以下幾個值:
|
|||||||||||||||||||||||||||||||||
cardIdentifier | 信用卡識別碼。每張信用卡只會對到一組識別碼。 | |||||||||||||||||||||||||||||||||
merchantReferenceInfo | 若商戶在 TapPay 後台使用 Co-brand card management 功能,且交易卡號符合設定時,將會回傳此參數,不支援 JKOPAY 商戶於TapPay後台設定的affiliate code management須限制於20字元內且為半形的英數字
|
Example
請參考我們的範例程式
Get CCV Prime
此串接內容適合用於『當使用 Pay by Card Token API 時,希望帶入 CCV 進行交易,但卻不想經手明碼 CCV』情境
透過 SDK 串接後, 可以使用 TPDCcv
類別中的 getPrime()
方法取得一串 ccv_prime, 並把 ccv_prime 帶入到 Pay by Card Token API 後即可進行交易
註: ccv_prime 為一串亂數, 並不是敏感資訊
Setup CCV Form
使用此方法設定 ccv 欄位
+ (instancetype)setupCCVWithContainer:(UIView *)view;
TPDCcvForm.setupCCV(withContainer: UIView)
Example
self.tpdCcvForm = [TPDCcvForm setupCCVWithContainer:self.ccvFormView];
tpdCcvForm = TPDCcvForm.setupCCV(withContainer: ccvFormView)
Setup Card Type
此方法可以驗證輸入的 ccv 格式,ex VISA 驗證 ccv 欄位是否輸入 3碼
- (void)setCCVFormCardType:(CardType) cardType;
tpdCcvForm.setCCVForm(cardType: CardType)
Example
[self.tpdCcvForm setCCVFormCardType:CardType_Visa];
tpdCcvForm.setCCVForm(CardType.visa)
onCCVFormUpdated
使用此方法可透過 callback 取得現在 ccv 輸入的狀態
- (instancetype _Nonnull)onCCVFormUpdated:(void (^)(TPDStatus * _Nullable))callback;
tpdCcvForm.onCCVFormUpdated(callback: (TPDStatus?) -> Void)
Example
[self.tpdCcvForm onCCVFormUpdated:^(TPDStatus * _Nullable status) {
NSLog(@"isCanGetCCVPrime : %d", [status isCanGetCCVPrime]);
}];
tpdCcvForm.onCCVFormUpdated { (status) in
print("isCanGetCCVPrime : \(status!.isCanGetCCVPrime())")
}
setup TPDCcv
使用此方法初始化 TPDCcv 物件
+ (instancetype _Nonnull)setup:(TPDCcvForm * _Nonnull)ccvForm;
tpdCcv = TPDCcv.setup(ccvForm: TPDCcvForm)
Example
TPDCcv * tpdCcv = [TPDCcv setup:self.tpdCcvForm];
TPDCcv.setup(self.tpdCcvForm)
Get Prime
呼叫 getPrime()
方法成功的話可透過 onSuccessCallback 取得 prime,若失敗會在 onFailureCallback 取得錯誤代碼、錯誤訊息
[[[tpdCcv onSuccessCallback:^(NSString * _Nonnull prime) {
// Send ccv_prime to pay by card token API
}]onFailureCallback:^(NSInteger status, NSString * _Nonnull message) {
NSLog(@"status : %d, message : %@", status, message);
}] getPrime];
tpdCcv.onSuccessCallback { (prime) in
// Send ccv_prime to Pay by card token API
}.onFailureCallback { (status, message) in
print("status : \(status), message : \(message)")
}.getPrime()
Get Device ID
若您有使用風險控制服務
呼叫 getDeviceId()
方法回傳裝置識別碼
[[TPDSetup shareInstance] getDeviceId];
TPDSetup.shareInstance().getDeviceId()