Skip to content

Commit

Permalink
Merge pull request #9 from payrails/PR-3766-cc-support
Browse files Browse the repository at this point in the history
PR-3766: Credit card support support
  • Loading branch information
grgmgd authored Jan 18, 2024
2 parents ff78fec + 9f315e3 commit cc68eeb
Show file tree
Hide file tree
Showing 21 changed files with 1,482 additions and 57 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

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

1 change: 1 addition & 0 deletions Payrails.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Pod::Spec.new do |spec|
checkout.source_files = "Payrails/Classes/Public/**/*.{swift}"
checkout.resources = "Payrails/Classes/Public/Assets/*.xcassets"
checkout.dependency 'PayPalCheckout'
checkout.dependency 'Skyflow'
end
end
68 changes: 64 additions & 4 deletions Payrails.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
07237D662A8248A2005BE43C /* KeyedDecodingContainer+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07237D652A8248A2005BE43C /* KeyedDecodingContainer+.swift */; };
073FF1EB2A837A2F00B50B76 /* PayrailsSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 073FF1EA2A837A2F00B50B76 /* PayrailsSession.swift */; };
074D63292A97870600675D61 /* StoredPayPalInstrument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 074D63282A97870600675D61 /* StoredPayPalInstrument.swift */; };
07512BF92AF50BC3003C30D1 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512BF82AF50BC3003C30D1 /* CardView.swift */; };
07512BFC2AF50ECD003C30D1 /* CardSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512BFB2AF50ECD003C30D1 /* CardSession.swift */; };
07512BFE2AF52197003C30D1 /* CardFormStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512BFD2AF52197003C30D1 /* CardFormStyle.swift */; };
07512C002AF5294A003C30D1 /* CardSubmitButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512BFF2AF5294A003C30D1 /* CardSubmitButton.swift */; };
07512C022AF53E82003C30D1 /* CardPaymentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512C012AF53E82003C30D1 /* CardPaymentHandler.swift */; };
07512C042AF8EBBE003C30D1 /* CardContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512C032AF8EBBE003C30D1 /* CardContainer.swift */; };
07512C062AF8FF99003C30D1 /* CardFormElementsGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07512C052AF8FF99003C30D1 /* CardFormElementsGenerator.swift */; };
075151572A7BE72600BC3560 /* Payrails.docc in Sources */ = {isa = PBXBuildFile; fileRef = 075151562A7BE72600BC3560 /* Payrails.docc */; };
0751515D2A7BE72600BC3560 /* Payrails.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 075151522A7BE72600BC3560 /* Payrails.framework */; };
075151622A7BE72600BC3560 /* PayrailsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075151612A7BE72600BC3560 /* PayrailsTests.swift */; };
075151632A7BE72600BC3560 /* Payrails.h in Headers */ = {isa = PBXBuildFile; fileRef = 075151552A7BE72600BC3560 /* Payrails.h */; settings = {ATTRIBUTES = (Public, ); }; };
075151752A7BE99500BC3560 /* Payrails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075151742A7BE99500BC3560 /* Payrails.swift */; };
075151772A7BEA4700BC3560 /* InitResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075151762A7BEA4700BC3560 /* InitResponse.swift */; };
07543DFE2B03E1420051E710 /* PaymentButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07543DFD2B03E1420051E710 /* PaymentButton.swift */; };
07543E002B03E16E0051E710 /* DropInPaymentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07543DFF2B03E16E0051E710 /* DropInPaymentView.swift */; };
07543E022B03E1930051E710 /* DropInCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07543E012B03E1930051E710 /* DropInCardView.swift */; };
0768572A2A83C7AF0070F081 /* PaymentPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 076857292A83C7AF0070F081 /* PaymentPresenter.swift */; };
0768572C2A83C7D70070F081 /* PaymentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0768572B2A83C7D70070F081 /* PaymentHandler.swift */; };
0768572E2A83C8370070F081 /* PaymentHandlerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0768572D2A83C8370070F081 /* PaymentHandlerDelegate.swift */; };
Expand All @@ -35,6 +44,8 @@
078489712A826A9200C29E6B /* ApplePayButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 078489702A826A9200C29E6B /* ApplePayButton.swift */; };
078489742A8272DC00C29E6B /* ApplePayHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 078489732A8272DC00C29E6B /* ApplePayHandler.swift */; };
078489762A8275FF00C29E6B /* SDKConfig+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 078489752A8275FF00C29E6B /* SDKConfig+.swift */; };
07F65A372AFD2FD20099812F /* DropInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07F65A362AFD2FD20099812F /* DropInView.swift */; };
07F65A392AFD2FEC0099812F /* DropInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07F65A382AFD2FEC0099812F /* DropInViewController.swift */; };
39AB4AE0E3BF68F5DD30A995 /* Pods_Payrails_PayrailsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B17C40BF69FF94C36BBBB39 /* Pods_Payrails_PayrailsTests.framework */; };
74A1AB30E90B2E626E8B73D8 /* Pods_Payrails.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08B60C8AE00088C3F8B99D2E /* Pods_Payrails.framework */; };
/* End PBXBuildFile section */
Expand All @@ -61,13 +72,22 @@
07237D652A8248A2005BE43C /* KeyedDecodingContainer+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+.swift"; sourceTree = "<group>"; };
073FF1EA2A837A2F00B50B76 /* PayrailsSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayrailsSession.swift; sourceTree = "<group>"; };
074D63282A97870600675D61 /* StoredPayPalInstrument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredPayPalInstrument.swift; sourceTree = "<group>"; };
07512BF82AF50BC3003C30D1 /* CardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
07512BFB2AF50ECD003C30D1 /* CardSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardSession.swift; sourceTree = "<group>"; };
07512BFD2AF52197003C30D1 /* CardFormStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardFormStyle.swift; sourceTree = "<group>"; };
07512BFF2AF5294A003C30D1 /* CardSubmitButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardSubmitButton.swift; sourceTree = "<group>"; };
07512C012AF53E82003C30D1 /* CardPaymentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPaymentHandler.swift; sourceTree = "<group>"; };
07512C032AF8EBBE003C30D1 /* CardContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardContainer.swift; sourceTree = "<group>"; };
07512C052AF8FF99003C30D1 /* CardFormElementsGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardFormElementsGenerator.swift; sourceTree = "<group>"; };
075151522A7BE72600BC3560 /* Payrails.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Payrails.framework; sourceTree = BUILT_PRODUCTS_DIR; };
075151552A7BE72600BC3560 /* Payrails.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Payrails.h; sourceTree = "<group>"; };
075151562A7BE72600BC3560 /* Payrails.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Payrails.docc; sourceTree = "<group>"; };
0751515C2A7BE72600BC3560 /* PayrailsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PayrailsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
075151612A7BE72600BC3560 /* PayrailsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayrailsTests.swift; sourceTree = "<group>"; };
075151742A7BE99500BC3560 /* Payrails.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Payrails.swift; sourceTree = "<group>"; };
075151762A7BEA4700BC3560 /* InitResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitResponse.swift; sourceTree = "<group>"; };
07543DFD2B03E1420051E710 /* PaymentButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButton.swift; sourceTree = "<group>"; };
07543DFF2B03E16E0051E710 /* DropInPaymentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropInPaymentView.swift; sourceTree = "<group>"; };
07543E012B03E1930051E710 /* DropInCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropInCardView.swift; sourceTree = "<group>"; };
076857292A83C7AF0070F081 /* PaymentPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentPresenter.swift; sourceTree = "<group>"; };
0768572B2A83C7D70070F081 /* PaymentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentHandler.swift; sourceTree = "<group>"; };
0768572D2A83C8370070F081 /* PaymentHandlerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentHandlerDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -79,6 +99,8 @@
078489702A826A9200C29E6B /* ApplePayButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplePayButton.swift; sourceTree = "<group>"; };
078489732A8272DC00C29E6B /* ApplePayHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplePayHandler.swift; sourceTree = "<group>"; };
078489752A8275FF00C29E6B /* SDKConfig+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SDKConfig+.swift"; sourceTree = "<group>"; };
07F65A362AFD2FD20099812F /* DropInView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropInView.swift; sourceTree = "<group>"; };
07F65A382AFD2FEC0099812F /* DropInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropInViewController.swift; sourceTree = "<group>"; };
08B60C8AE00088C3F8B99D2E /* Pods_Payrails.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Payrails.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0B17C40BF69FF94C36BBBB39 /* Pods_Payrails_PayrailsTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Payrails_PayrailsTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4A793496DB427F57490FD397 /* Pods-Payrails-PayrailsTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Payrails-PayrailsTests.release.xcconfig"; path = "Target Support Files/Pods-Payrails-PayrailsTests/Pods-Payrails-PayrailsTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -126,6 +148,7 @@
07237D632A814D95005BE43C /* Public */ = {
isa = PBXGroup;
children = (
07512BFA2AF50EBC003C30D1 /* Helpers */,
071E35502A8B73A7007E5704 /* Assets */,
076857282A83C7A80070F081 /* Protocols */,
078489722A8270AC00C29E6B /* PaymentHelpers */,
Expand All @@ -149,6 +172,29 @@
path = Extensions;
sourceTree = "<group>";
};
07512BF72AF50BB7003C30D1 /* Card */ = {
isa = PBXGroup;
children = (
07F65A362AFD2FD20099812F /* DropInView.swift */,
07543E012B03E1930051E710 /* DropInCardView.swift */,
07543DFF2B03E16E0051E710 /* DropInPaymentView.swift */,
07512BF82AF50BC3003C30D1 /* CardView.swift */,
07543DFD2B03E1420051E710 /* PaymentButton.swift */,
);
path = Card;
sourceTree = "<group>";
};
07512BFA2AF50EBC003C30D1 /* Helpers */ = {
isa = PBXGroup;
children = (
07512BFB2AF50ECD003C30D1 /* CardSession.swift */,
07512C032AF8EBBE003C30D1 /* CardContainer.swift */,
07512BFD2AF52197003C30D1 /* CardFormStyle.swift */,
07512C052AF8FF99003C30D1 /* CardFormElementsGenerator.swift */,
);
path = Helpers;
sourceTree = "<group>";
};
075151482A7BE72600BC3560 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -194,7 +240,6 @@
071E35432A853040007E5704 /* PaymentFlow.swift */,
07237D5E2A814824005BE43C /* SDKConfig.swift */,
0776F2082A824F2800B238E6 /* PayrailsError.swift */,
075151762A7BEA4700BC3560 /* InitResponse.swift */,
076AACE22A8142D400D4DB6B /* Configuration.swift */,
0776F2062A824CEC00B238E6 /* Callbacks.swift */,
0784896D2A8267CD00C29E6B /* PaymentType.swift */,
Expand Down Expand Up @@ -225,8 +270,11 @@
0784896F2A826A8000C29E6B /* Views */ = {
isa = PBXGroup;
children = (
07512BF72AF50BB7003C30D1 /* Card */,
078489702A826A9200C29E6B /* ApplePayButton.swift */,
071E354C2A8B6EE5007E5704 /* PayPalButton.swift */,
07512BFF2AF5294A003C30D1 /* CardSubmitButton.swift */,
07F65A382AFD2FEC0099812F /* DropInViewController.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -235,6 +283,7 @@
isa = PBXGroup;
children = (
078489732A8272DC00C29E6B /* ApplePayHandler.swift */,
07512C012AF53E82003C30D1 /* CardPaymentHandler.swift */,
071E35532A8B75A0007E5704 /* PayPalHandler.swift */,
071E353B2A84F83A007E5704 /* PayrailsAPI.swift */,
);
Expand Down Expand Up @@ -458,7 +507,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
075151772A7BEA4700BC3560 /* InitResponse.swift in Sources */,
07F65A392AFD2FEC0099812F /* DropInViewController.swift in Sources */,
07543E022B03E1930051E710 /* DropInCardView.swift in Sources */,
0768572C2A83C7D70070F081 /* PaymentHandler.swift in Sources */,
073FF1EB2A837A2F00B50B76 /* PayrailsSession.swift in Sources */,
071E35462A85567F007E5704 /* KeyedEncodingContainer+.swift in Sources */,
Expand All @@ -467,16 +517,26 @@
078489762A8275FF00C29E6B /* SDKConfig+.swift in Sources */,
07237D5F2A814824005BE43C /* SDKConfig.swift in Sources */,
0776F2072A824CEC00B238E6 /* Callbacks.swift in Sources */,
07543E002B03E16E0051E710 /* DropInPaymentView.swift in Sources */,
07F65A372AFD2FD20099812F /* DropInView.swift in Sources */,
078489712A826A9200C29E6B /* ApplePayButton.swift in Sources */,
071E35562A8CD8EA007E5704 /* JSONDecoder+.swift in Sources */,
07512C002AF5294A003C30D1 /* CardSubmitButton.swift in Sources */,
075151752A7BE99500BC3560 /* Payrails.swift in Sources */,
07512C042AF8EBBE003C30D1 /* CardContainer.swift in Sources */,
07512BFC2AF50ECD003C30D1 /* CardSession.swift in Sources */,
0784896E2A8267CD00C29E6B /* PaymentType.swift in Sources */,
071E354D2A8B6EE5007E5704 /* PayPalButton.swift in Sources */,
07512BF92AF50BC3003C30D1 /* CardView.swift in Sources */,
071E353C2A84F83A007E5704 /* PayrailsAPI.swift in Sources */,
0781E6352A9F391D00073068 /* InitData.swift in Sources */,
07512BFE2AF52197003C30D1 /* CardFormStyle.swift in Sources */,
07237D662A8248A2005BE43C /* KeyedDecodingContainer+.swift in Sources */,
0776F2092A824F2800B238E6 /* PayrailsError.swift in Sources */,
07543DFE2B03E1420051E710 /* PaymentButton.swift in Sources */,
07512C022AF53E82003C30D1 /* CardPaymentHandler.swift in Sources */,
0768572A2A83C7AF0070F081 /* PaymentPresenter.swift in Sources */,
07512C062AF8FF99003C30D1 /* CardFormElementsGenerator.swift in Sources */,
074D63292A97870600675D61 /* StoredPayPalInstrument.swift in Sources */,
076AACE32A8142D400D4DB6B /* Configuration.swift in Sources */,
0768572E2A83C8370070F081 /* PaymentHandlerDelegate.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Payrails/Classes/Public/Domains/PaymentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import UIKit

public extension Payrails {
enum PaymentType: String, Decodable {
case payPal, applePay
case payPal, applePay, card
}
}
3 changes: 3 additions & 0 deletions Payrails/Classes/Public/Domains/PayrailsError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum PayrailsError: Error, LocalizedError {
case sdkNotInitialized
case missingData(String?)
case invalidDataFormat
case invalidCardData
case unknown(error: Error?)
case unsupportedPayment(type: Payrails.PaymentType)
case incorrectPaymentSetup(type: Payrails.PaymentType)
Expand All @@ -19,6 +20,8 @@ public extension PayrailsError {
return "Payrails SDK has not been properly initialized"
case .invalidDataFormat:
return "Provided Config data is invalid and can not be parsed"
case .invalidCardData:
return "Invalid Card Data provided"
case .unknown(let error):
return error?.localizedDescription ?? "Unknown error appeared"
case let.missingData(missingData):
Expand Down
45 changes: 45 additions & 0 deletions Payrails/Classes/Public/Domains/SDKConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ struct Status: Decodable {

struct ExecutionLinks: Decodable {
let `self`: String
let threeDS: String?
let lookup: Link?
let confirm: Link?

enum CodingKeys: String, CodingKey {
case `self`
case threeDS = "3ds"
case lookup
case confirm
}
}

struct Workflow: Decodable {
Expand Down Expand Up @@ -125,9 +133,36 @@ struct PaymentOptions: Decodable {

enum PaymentInstrument {
case paypal([PayPalPaymentInstrument])
case card([CardInstrument])
}

struct CardInstrument: StoredInstrument, Decodable {
var id: String

var email: String? { nil }

var description: String? { String(format: "%@***%@", data?.bin ?? "", data?.suffix ?? "") }

var type: Payrails.PaymentType {
.card
}

let createdAt: String
let status: String
let data: CardInstrumentData?
}


struct CardInstrumentData: Decodable {
let bin: String?
let suffix: String?
}

struct PayPalPaymentInstrument: StoredInstrument, Decodable {
var description: String? {
email
}

var email: String? {
data?.email
}
Expand Down Expand Up @@ -195,6 +230,16 @@ struct PaymentOptions: Decodable {
case .applePay:
config = .applePay(try container.decode(ApplePayConfig.self, forKey: .config))
paymentInstruments = nil

case .card:
config = nil

if let element = try? container.decode([CardInstrument].self, forKey: .paymentInstruments) {
paymentInstruments = .card(element)
} else {
paymentInstruments = nil
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public protocol StoredInstrument {
var id: String { get }
var email: String? { get }
var description: String? { get }
var type: Payrails.PaymentType { get }
}
6 changes: 6 additions & 0 deletions Payrails/Classes/Public/Helpers/CardContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import Skyflow

protocol CardContainer {
func collect(with callback: Skyflow.Callback)
}
Loading

0 comments on commit cc68eeb

Please sign in to comment.