Skip to content

Commit

Permalink
Merge pull request #82 from xendit/feat/add-cardholder-information
Browse files Browse the repository at this point in the history
add card holder information on createToken and createAuthentication
  • Loading branch information
adhiartaputra authored Aug 1, 2024
2 parents cf4f96c + b98f5fa commit 414c35c
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Slack Mentions: `@troops-cards`
Add this to your Podfile.

```ruby
pod 'Xendit', '~> 3.7.0'
pod 'Xendit', '~> 3.9.0'
```

**Important:** Import SDK in Objective-C project with CocoaPods integration, you can do as following
Expand Down
8 changes: 7 additions & 1 deletion Sources/Xendit/Models/DTOs/XenditAuthenticationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import Foundation
public var midLabel: String?
public var billingDetails: XenditBillingDetails?
public var customer: XenditCustomer?
public var cardData: XenditCardHolderInformation?

public init(tokenId: String, amount: NSNumber, currency: String) {
public init(tokenId: String, amount: NSNumber, currency: String, cardData: XenditCardHolderInformation?) {
self.amount = amount
self.tokenId = tokenId
self.currency = currency
self.cardData = cardData
}

func toJsonObject() -> [String : Any] {
Expand All @@ -47,6 +49,10 @@ import Foundation
if (customer != nil) {
json["customer"] = customer!.toJsonObject()
}

if (cardData != nil) {
json["card_data"] = cardData!.toJsonObject()
}

return json
}
Expand Down
28 changes: 27 additions & 1 deletion Sources/Xendit/Models/DTOs/XenditCardData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,36 @@ import Foundation
// Card verification number (CVN) value
open var cardCvn: String?

public init(cardNumber: String, cardExpMonth: String, cardExpYear: String) {
// Card holder first name value
open var cardHolderFirstName: String?

// Card holder first name value
open var cardHolderLastName: String?

// Card holder first name value
open var cardHolderEmail: String?

// Card holder first name value
open var cardHolderPhoneNumber: String?



public init(
cardNumber: String,
cardExpMonth: String,
cardExpYear: String,
cardHolderFirstName: String? = nil,
cardHolderLastName: String? = nil,
cardHolderEmail: String? = nil,
cardHolderPhoneNumber: String? = nil
) {
self.cardNumber = cardNumber
self.cardExpMonth = cardExpMonth
self.cardExpYear = cardExpYear
self.cardHolderFirstName = cardHolderFirstName
self.cardHolderLastName = cardHolderLastName
self.cardHolderEmail = cardHolderEmail
self.cardHolderPhoneNumber = cardHolderPhoneNumber
}

}
45 changes: 45 additions & 0 deletions Sources/Xendit/Models/DTOs/XenditCardHolderInformation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// XenditCardHolderInformation.swift
// Xendit
//
// Created by xendit on 07/07/21.
//

import Foundation
@objcMembers
@objc(XenditCardHolderInformation) open class XenditCardHolderInformation: NSObject {

// Card holder first name value
open var cardHolderFirstName: String?

// Card holder first name value
open var cardHolderLastName: String?

// Card holder first name value
open var cardHolderEmail: String?

// Card holder first name value
open var cardHolderPhoneNumber: String?

public init(
cardHolderFirstName: String? = nil,
cardHolderLastName: String? = nil,
cardHolderEmail: String? = nil,
cardHolderPhoneNumber: String? = nil
) {
self.cardHolderFirstName = cardHolderFirstName
self.cardHolderLastName = cardHolderLastName
self.cardHolderEmail = cardHolderEmail
self.cardHolderPhoneNumber = cardHolderPhoneNumber
}

func toJsonObject() -> [String : Any] {
var json: [String: Any] = [:]
if cardHolderFirstName != nil { json["card_holder_first_name"] = cardHolderFirstName }
if cardHolderLastName != nil { json["card_holder_last_name"] = cardHolderLastName }
if cardHolderEmail != nil { json["card_holder_email"] = cardHolderEmail }
if cardHolderPhoneNumber != nil { json["card_holder_mobile_number"] = cardHolderPhoneNumber }
return json
}

}
18 changes: 16 additions & 2 deletions Sources/Xendit/Models/DTOs/XenditTokenizationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ import Foundation

@available(*, deprecated, message: "Use init(cardData: XenditCardData, isSingleUse: Bool, shouldAuthenticate: Bool, amount: NSNumber, currency: String) instead" )
public init(cardData: CardData, shouldAuthenticate: Bool) {
self.cardData = XenditCardData.init(cardNumber: cardData.cardNumber, cardExpMonth: cardData.cardExpMonth, cardExpYear: cardData.cardExpYear)
self.cardData = XenditCardData.init(
cardNumber: cardData.cardNumber,
cardExpMonth: cardData.cardExpMonth,
cardExpYear: cardData.cardExpYear
)
self.cardData.cardCvn = cardData.cardCvn
self.isSingleUse = !cardData.isMultipleUse
self.shouldAuthenticate = shouldAuthenticate
self.amount = cardData.amount
self.currency = cardData.currency
}

public init (cardData: XenditCardData, isSingleUse: Bool, shouldAuthenticate: Bool, amount: NSNumber?, currency: String?) {
public init (
cardData: XenditCardData,
isSingleUse: Bool,
shouldAuthenticate: Bool,
amount: NSNumber?,
currency: String?
) {
self.cardData = cardData
self.isSingleUse = isSingleUse
self.shouldAuthenticate = shouldAuthenticate
Expand All @@ -45,6 +55,10 @@ import Foundation
"account_number": cardData.cardNumber,
"exp_month": cardData.cardExpMonth,
"exp_year": cardData.cardExpYear,
"card_holder_first_name": cardData.cardHolderFirstName ?? "",
"card_holder_last_name": cardData.cardHolderLastName ?? "",
"card_holder_email": cardData.cardHolderEmail ?? "",
"card_holder_phone_number": cardData.cardHolderPhoneNumber ?? ""
]

if cardData.cardCvn != nil && cardData.cardCvn != "" {
Expand Down
71 changes: 66 additions & 5 deletions Sources/Xendit/XDTCards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,81 @@ public class XDTCards: CanTokenize, CanAuthenticate {

public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, onBehalfOf: String?, customer: XenditCustomer?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {

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

public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, currency: String?, onBehalfOf: String?, customer: XenditCustomer?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {

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

public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, currency: String?, onBehalfOf: String?, customer: XenditCustomer?, cardCvn: String?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {
public static func createAuthentication(
fromViewController: UIViewController,
tokenId: String,
amount: NSNumber,
currency: String?,
onBehalfOf: String?,
customer: XenditCustomer?,
cardCvn: String?,
completion: @escaping (XenditAuthentication?, XenditError?) -> Void
) {
createAuthentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: nil,
onBehalfOf: onBehalfOf,
customer: customer,
cardCvn: nil,
cardData: nil,
completion: completion
);
}

public static func createAuthentication(
fromViewController: UIViewController,
tokenId: String,
amount: NSNumber,
currency: String?,
onBehalfOf: String?,
customer: XenditCustomer?,
cardCvn: String?,
cardData: XenditCardHolderInformation?,
completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {
if publishableKey == nil {
completion(nil, XenditError(errorCode: "VALIDATION_ERROR", message: "Empty publishable key"))
return
}

create3DS1Authentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: currency, onBehalfOf: onBehalfOf, cardCvn: cardCvn, completion: completion)
create3DS1Authentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: currency,
onBehalfOf: onBehalfOf,
cardCvn: cardCvn,
cardData:cardData,
completion: completion
)
}

private static func create3DS1Authentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, currency: String?, onBehalfOf: String?, cardCvn: String?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {
private static func create3DS1Authentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, currency: String?, onBehalfOf: String?, cardCvn: String?, cardData: XenditCardHolderInformation?, completion: @escaping (XenditAuthentication?, XenditError?) -> Void) {
if publishableKey == nil {
completion(nil, XenditError(errorCode: "VALIDATION_ERROR", message: "Empty publishable key"))
return
Expand All @@ -156,6 +213,10 @@ public class XDTCards: CanTokenize, CanAuthenticate {
requestBody["card_cvn"] = cardCvn
}

if let cardData {
requestBody["card_data"] = cardData
}

var extraHeaders: [String: String] = [:]
if onBehalfOf != nil || onBehalfOf != "" {
extraHeaders["for-user-id"] = onBehalfOf
Expand Down
2 changes: 1 addition & 1 deletion Xendit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Xendit'
s.version = '3.8.7'
s.version = '3.9.0'
s.license = 'MIT'
s.homepage = 'https://www.xendit.co'
s.author = { 'Juan Gonzalez’' => '[email protected]' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "OHHTTPStubs",
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs.git",
"state": {
"branch": null,
"revision": "12f19662426d0434d6c330c6974d53e2eb10ecd9",
"version": "9.1.0"
}
},
{
"package": "Sentry",
"repositoryURL": "https://github.com/getsentry/sentry-cocoa.git",
"state": {
"branch": null,
"revision": "5421f94cc859eb65f5ae3866165a053aa634431e",
"version": "8.32.0"
}
}
]
},
"version": 1
}
Loading

0 comments on commit 414c35c

Please sign in to comment.