Skip to content

Commit 353aa87

Browse files
authored
Merge pull request #63 from xendit/CC-8199/rename-retokenize-as-storecvn
[CC-8199] Add storeCVN function
2 parents 101b077 + 7db9e3a commit 353aa87

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// XenditStoreCVNRequest.swift
3+
// Xendit
4+
//
5+
// Created by xendit on 9/3/23.
6+
//
7+
8+
import Foundation
9+
10+
@objcMembers
11+
@objc(XenditStoreCVNRequest) public class XenditStoreCVNRequest: XenditRetokenizationRequest {
12+
13+
public override init (tokenId: String) {
14+
super.init(tokenId: tokenId)
15+
}
16+
}

Sources/Xendit/XDTCards.swift

+28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ protocol CanTokenize {
2020
// @param onBehalfOf (Optional) Business id for xenPlaform use cases
2121
// @param completion callback function when tokenization is completed
2222
static func createToken(fromViewController: UIViewController, retokenizationRequest: XenditRetokenizationRequest, onBehalfOf: String?, completion: @escaping (XenditCCToken?, XenditError?) -> Void)
23+
24+
// Store CVN method
25+
// @param storeCVNRequest: Token ID and billing details
26+
// @param onBehalfOf (Optional) Business id for xenPlaform use cases
27+
// @param completion callback function when tokenization is completed
28+
static func storeCVN(fromViewController: UIViewController, storeCVNRequest: XenditStoreCVNRequest, onBehalfOf: String?, completion: @escaping (XenditCCToken?, XenditError?) -> Void)
2329
}
2430

2531
protocol CanAuthenticate {
@@ -70,6 +76,7 @@ public class XDTCards: CanTokenize, CanAuthenticate {
7076
}
7177
}
7278

79+
@available(*, deprecated, message: "Use storeCVN(UIViewController, XenditStoreCVNRequest, String, Callback) instead")
7380
public static func createToken(fromViewController: UIViewController, retokenizationRequest: XenditRetokenizationRequest, onBehalfOf: String?, completion: @escaping (XenditCCToken?, XenditError?) -> Void) {
7481
let logPrefix = "createToken:"
7582

@@ -91,6 +98,27 @@ public class XDTCards: CanTokenize, CanAuthenticate {
9198
}
9299
}
93100

101+
public static func storeCVN(fromViewController: UIViewController, storeCVNRequest: XenditStoreCVNRequest, onBehalfOf: String?, completion: @escaping (XenditCCToken?, XenditError?) -> Void) {
102+
let logPrefix = "storeCVN:"
103+
104+
if let error = validateRetokenizationRequest(retokenizationRequest: storeCVNRequest) {
105+
Log.shared.verbose("\(logPrefix) \(error)")
106+
completion(nil, error)
107+
}
108+
109+
var extraHeaders: [String: String] = [:]
110+
if onBehalfOf != "" {
111+
extraHeaders["for-user-id"] = onBehalfOf
112+
}
113+
114+
let requestBody = storeCVNRequest.toJsonObject()
115+
116+
XDTApiClient.createTokenRequest(publishableKey: publishableKey!, bodyJson: requestBody, extraHeader: extraHeaders) { (authenticatedToken, error) in
117+
118+
handleCreditCardTokenization(fromViewController: fromViewController, authenticatedToken: authenticatedToken, amount: 0, currency: nil, onBehalfOf: onBehalfOf, cardCvn: storeCVNRequest.cardCvn, error: error, completion: completion)
119+
}
120+
}
121+
94122
public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, onBehalfOf: String?, customer: XenditCustomer?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {
95123

96124
createAuthentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: nil, onBehalfOf: onBehalfOf, customer: customer, completion: completion);

Sources/Xendit/Xendit.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@ import XenditObjC
2626
XDTCards.createToken(fromViewController: fromViewController, tokenizationRequest: tokenizationRequest, onBehalfOf: onBehalfOf, completion: completion)
2727
}
2828

29-
// Create token method with billing details and customer object
29+
// Retokenize method with billing details and customer object
30+
@available(*, deprecated, message: "Use storeCVN(UIViewController, XenditStoreCVNRequest, String, Callback) instead")
3031
public static func createToken(fromViewController: UIViewController, retokenizationRequest: XenditRetokenizationRequest, onBehalfOf: String?, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
3132
XDTCards.setup(publishableKey: publishableKey!)
3233
XDTCards.createToken(fromViewController: fromViewController, retokenizationRequest: retokenizationRequest, onBehalfOf: onBehalfOf, completion: completion)
3334
}
3435

36+
// Store CVN with existing token method with billing details and customer object
37+
public static func storeCVN(
38+
fromViewController: UIViewController,
39+
storeCVNRequest: XenditStoreCVNRequest,
40+
onBehalfOf: String?,
41+
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
42+
XDTCards.setup(publishableKey: publishableKey!)
43+
XDTCards.storeCVN(fromViewController: fromViewController, storeCVNRequest: storeCVNRequest, onBehalfOf: onBehalfOf, completion: completion)
44+
}
45+
3546
public static func createAuthentication(fromViewController: UIViewController, authenticationRequest: XenditAuthenticationRequest, onBehalfOf: String?, completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void) {
3647
XDTCards.setup(publishableKey: publishableKey!)
3748
let tokenId = authenticationRequest.tokenId

Xendit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Xendit'
3-
s.version = '3.7.1'
3+
s.version = '3.8.0'
44
s.license = 'MIT'
55
s.homepage = 'https://www.xendit.co'
66
s.author = { 'Juan Gonzalez’' => '[email protected]' }

Xendit.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24+
A1F7B53429B96F860063AE15 /* XenditStoreCVNRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1F7B53329B96F860063AE15 /* XenditStoreCVNRequest.swift */; };
2425
OBJ_111 /* HTTPStubs+NSURLSessionConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_74 /* HTTPStubs+NSURLSessionConfiguration.m */; };
2526
OBJ_112 /* HTTPStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_75 /* HTTPStubs.m */; };
2627
OBJ_113 /* HTTPStubsMethodSwizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_76 /* HTTPStubsMethodSwizzling.m */; };
@@ -148,6 +149,7 @@
148149
/* End PBXCopyFilesBuildPhase section */
149150

150151
/* Begin PBXFileReference section */
152+
A1F7B53329B96F860063AE15 /* XenditStoreCVNRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XenditStoreCVNRequest.swift; sourceTree = "<group>"; };
151153
OBJ_10 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
152154
OBJ_101 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
153155
OBJ_102 /* Xendit.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Xendit.podspec; sourceTree = "<group>"; };
@@ -313,6 +315,7 @@
313315
OBJ_25 /* XenditJWT.swift */,
314316
OBJ_26 /* XenditJWTRequest.swift */,
315317
OBJ_27 /* XenditRetokenizationRequest.swift */,
318+
A1F7B53329B96F860063AE15 /* XenditStoreCVNRequest.swift */,
316319
OBJ_28 /* XenditTokenizationRequest.swift */,
317320
);
318321
path = DTOs;
@@ -714,6 +717,7 @@
714717
isa = PBXSourcesBuildPhase;
715718
buildActionMask = 0;
716719
files = (
720+
A1F7B53429B96F860063AE15 /* XenditStoreCVNRequest.swift in Sources */,
717721
OBJ_139 /* Extensions.swift in Sources */,
718722
OBJ_140 /* Log.swift in Sources */,
719723
OBJ_141 /* LogSanitizer.swift in Sources */,

0 commit comments

Comments
 (0)