Skip to content

Commit

Permalink
Merge pull request #38 from xendit/CC-4890/allow-example-to-handle-de…
Browse files Browse the repository at this point in the history
…cimals

Fixed examples to handle decimals
  • Loading branch information
javiersuweijie authored Jul 21, 2021
2 parents 67872fb + fb92546 commit f520b9c
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 67 deletions.
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.3.0"
s.version = "3.4.0"
s.summary = "Xendit is an API for accepting payments online"
s.homepage = "https://www.xendit.co"
s.license = "MIT"
Expand Down
8 changes: 8 additions & 0 deletions Xendit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
845651DB25495D38005B997C /* CardinalMobile.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 845651D6254947FD005B997C /* CardinalMobile.framework */; };
845651DC25495D38005B997C /* CardinalMobile.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 845651D6254947FD005B997C /* CardinalMobile.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
845651E2254AAC32005B997C /* Jsonable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845651E1254AAC32005B997C /* Jsonable.swift */; };
8459CE87269583B800D54A4C /* XenditAuthenticationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459CE86269583B800D54A4C /* XenditAuthenticationRequest.swift */; };
8459CE8A269588C300D54A4C /* XenditCardData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459CE89269588C300D54A4C /* XenditCardData.swift */; };
8482C71223BD911C00618F01 /* Xendit3DSRecommendation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8482C71123BD911C00618F01 /* Xendit3DSRecommendation.swift */; };
8484F3A526423CF6001E37D0 /* JsonEncodeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8484F3A426423CF6001E37D0 /* JsonEncodeTest.swift */; };
84A9F66C2553D77D00B735F8 /* XenditJWTRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A9F66B2553D77D00B735F8 /* XenditJWTRequest.swift */; };
Expand Down Expand Up @@ -159,6 +161,8 @@
845651D225491B50005B997C /* XDTApiClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XDTApiClient.swift; sourceTree = "<group>"; };
845651D6254947FD005B997C /* CardinalMobile.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CardinalMobile.framework; sourceTree = "<group>"; };
845651E1254AAC32005B997C /* Jsonable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Jsonable.swift; sourceTree = "<group>"; };
8459CE86269583B800D54A4C /* XenditAuthenticationRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XenditAuthenticationRequest.swift; sourceTree = "<group>"; };
8459CE89269588C300D54A4C /* XenditCardData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XenditCardData.swift; sourceTree = "<group>"; };
8482C71123BD911C00618F01 /* Xendit3DSRecommendation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Xendit3DSRecommendation.swift; sourceTree = "<group>"; };
8484F3A426423CF6001E37D0 /* JsonEncodeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JsonEncodeTest.swift; sourceTree = "<group>"; };
84A9F66B2553D77D00B735F8 /* XenditJWTRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XenditJWTRequest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -301,6 +305,8 @@
841816BB254ABDF400CC81AD /* XenditTokenizationRequest.swift */,
841816BF254BF30900CC81AD /* XenditJWT.swift */,
84A9F66B2553D77D00B735F8 /* XenditJWTRequest.swift */,
8459CE86269583B800D54A4C /* XenditAuthenticationRequest.swift */,
8459CE89269588C300D54A4C /* XenditCardData.swift */,
);
path = DTOs;
sourceTree = "<group>";
Expand Down Expand Up @@ -558,6 +564,7 @@
files = (
841816C0254BF30900CC81AD /* XenditJWT.swift in Sources */,
94AD221C1E855440009C00D5 /* XenditTokenCredentials.swift in Sources */,
8459CE8A269588C300D54A4C /* XenditCardData.swift in Sources */,
A05650EE1EBC511E0019B64F /* XenditAuthentication.swift in Sources */,
845651E2254AAC32005B997C /* Jsonable.swift in Sources */,
841816B5254AB5F400CC81AD /* XenditAddress.swift in Sources */,
Expand All @@ -573,6 +580,7 @@
A05650F41EBC635E0019B64F /* AuthenticationData.swift in Sources */,
845651CF25490A47005B997C /* Authenticatable.swift in Sources */,
940EA6481E82EEFA004ADA90 /* XenditCCToken.swift in Sources */,
8459CE87269583B800D54A4C /* XenditAuthenticationRequest.swift in Sources */,
841816B7254AB60F00CC81AD /* XenditBillingDetails.swift in Sources */,
841816B9254AB7FE00CC81AD /* XenditCustomer.swift in Sources */,
39C01AE0218B45AB0035C82C /* ISHLogDNAService.m in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Xendit/Models/AuthenticationData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation

@available(*, deprecated, message: "Use XenditAuthenticationRequest instead")
@objcMembers
@objc(XENAuthenticationData) open class AuthenticationData: NSObject {

Expand All @@ -20,5 +21,8 @@ import Foundation
// Card transaction amount
open var amount: NSNumber!

// Transaction currency
open var currency: String?

}

1 change: 1 addition & 0 deletions Xendit/Models/CardData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum CYBCardTypes {
// Multiple use flag
open var isMultipleUse: Bool

@available(*, deprecated, message: "Use XenditCardData instead")
public override init() {
self.isMultipleUse = false
self.amount = 0;
Expand Down
53 changes: 53 additions & 0 deletions Xendit/Models/DTOs/XenditAuthenticationRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// XenditAuthenticationRequest.swift
// Xendit
//
// Created by xendit on 07/07/21.
//

import Foundation

@objcMembers
@objc(XenditAuthenticationRequest) open class XenditAuthenticationRequest: NSObject, JsonSerializable {

public var amount: NSNumber
public var tokenId: String
public var currency: String
public var cardCvn: String?
public var midLabel: String?
public var billingDetails: XenditBillingDetails?
public var customer: XenditCustomer?

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

func toJsonObject() -> [String : Any] {

var json: [String: Any] = [
"amount": amount,
"credit_card_token_id": tokenId,
"currency": currency
]

if (midLabel != nil) {
json["mid_label"] = midLabel
}

if (billingDetails != nil) {
json["billing_details"] = billingDetails!.toJsonObject()
}

if (cardCvn != nil) {
json["card_cvn"] = cardCvn
}

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

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

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

// Card Number value
open var cardNumber: String

// Card expiration month value
open var cardExpMonth: String

// Card expiration year value
open var cardExpYear: String

// Card verification number (CVN) value
open var cardCvn: String?

public init(cardNumber: String, cardExpMonth: String, cardExpYear: String) {
self.cardNumber = cardNumber
self.cardExpMonth = cardExpMonth
self.cardExpYear = cardExpYear
}

}
22 changes: 16 additions & 6 deletions Xendit/Models/DTOs/XenditTokenizationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@

import Foundation

public class XenditTokenizationRequest: JsonSerializable {
@objcMembers
@objc(XenditTokenizationRequest) public class XenditTokenizationRequest: NSObject, JsonSerializable {

public var amount: NSNumber
public var isSingleUse: Bool
public var shouldAuthenticate: Bool
public var cardData: CardData
public var cardData: XenditCardData
public var midLabel: String?
public var currency: String?
public var billingDetails: XenditBillingDetails?
public var customer: XenditCustomer?

@available(*, deprecated, message: "Use init(cardData: XenditCardData, isSingleUse: Bool, shouldAuthenticate: Bool, amount: NSNumber, currency: String) instead" )
public init(cardData: CardData, shouldAuthenticate: Bool) {
self.cardData = cardData
self.cardData = XenditCardData.init(cardNumber: cardData.cardNumber, cardExpMonth: cardData.cardExpMonth, cardExpYear: cardData.cardExpYear)
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?) {
self.cardData = cardData
self.isSingleUse = isSingleUse
self.shouldAuthenticate = shouldAuthenticate
self.amount = amount
self.currency = currency
}

func toJsonObject() -> [String : Any] {
// To be refactored using a request API DTO
var cardDataJson: [String: String] = [
Expand All @@ -41,15 +51,15 @@ public class XenditTokenizationRequest: JsonSerializable {
var json: [String: Any] = [
"should_authenticate": shouldAuthenticate,
"card_data": cardDataJson,
"is_single_use": !cardData.isMultipleUse
"is_single_use": isSingleUse
]

if (currency != nil) {
json["currency"] = currency;
}

if (!cardData.isMultipleUse) {
json["amount"] = cardData.amount;
if (isSingleUse) {
json["amount"] = amount;
}

if (billingDetails != nil) {
Expand Down
1 change: 1 addition & 0 deletions Xendit/Models/XenditAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Foundation
if status != nil { json["status"] = status }
if authenticationURL != nil { json["authentication_url"] = authenticationURL }
if authenticationTransactionId != nil { json["authentication_transaction_id"] = authenticationTransactionId }
if tokenId != nil { json["credit_card_token_id"] = tokenId }
if requestPayload != nil { json["pa_res"] = requestPayload }
if maskedCardNumber != nil { json["masked_card_number"] = maskedCardNumber }
if cardInfo != nil { json["card_info"] = cardInfo?.toJsonObject() }
Expand Down
Loading

0 comments on commit f520b9c

Please sign in to comment.