Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eligibility API logic #286

Merged
merged 56 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2a07770
Add EligibilityRequest file
richherrera Jul 11, 2024
f50baa8
Add EligibilityResult file
richherrera Jul 11, 2024
e564f3e
Add EligibilityClient file
richherrera Jul 11, 2024
193ab5c
Add EligilibilityClient method
richherrera Jul 11, 2024
de28ce6
Add Result properties
richherrera Jul 11, 2024
fc37fd6
Add request properties
richherrera Jul 11, 2024
de7bf1a
Add EligibilityVariables file
richherrera Jul 11, 2024
e0573a1
Remove header
richherrera Jul 11, 2024
c0000b4
Add EligibilityAPI
richherrera Jul 11, 2024
8a9f7e0
Sort directory
richherrera Jul 11, 2024
fa4863c
Add properties and initializers
richherrera Jul 11, 2024
e366890
Add tests files
richherrera Jul 11, 2024
bfd4749
Fix lints
richherrera Jul 11, 2024
a3000a1
Fix lint
richherrera Jul 11, 2024
f63935d
PR Feedback
richherrera Jul 15, 2024
fdc17bf
Conform Encodable and add variable eligibility variables properties
richherrera Jul 15, 2024
26b72e4
Add supported currency type enum
richherrera Jul 15, 2024
7fb6765
Add eligibility intent enum
richherrera Jul 15, 2024
8daa52b
Add eligibility result properties
richherrera Jul 15, 2024
4198535
Add Eligibility Response object
richherrera Jul 15, 2024
c1b1a75
Sort files Eligibility directory
richherrera Jul 15, 2024
3d41794
Update eligibility request with enum types
richherrera Jul 15, 2024
7ff6bb1
Add parameters and initializer on Client
richherrera Jul 15, 2024
1a34e59
Add API logic
richherrera Jul 15, 2024
4a87950
Add mock and remove intent enum
richherrera Jul 15, 2024
d8b3b76
Remove final
richherrera Jul 15, 2024
805304d
Add docstrings on Client
richherrera Jul 15, 2024
8dbf00c
Expose intents
richherrera Jul 15, 2024
32dddf8
Change Decodable instead of Codable for response model
richherrera Jul 15, 2024
65749c2
Update Variables struct
richherrera Jul 15, 2024
fed4f0c
Remove currency enum
richherrera Jul 15, 2024
a5aec4c
Add docstring for Request model
richherrera Jul 15, 2024
64c6cee
Add mock API
richherrera Jul 15, 2024
2408217
Add client tests
richherrera Jul 15, 2024
3a0c83a
Add Result docstrings
richherrera Jul 15, 2024
f6de949
Rename curency to currencyCode
richherrera Jul 15, 2024
2e15a23
Add marks
richherrera Jul 15, 2024
2cd8c4b
Fix merge conflicts
richherrera Jul 15, 2024
2ede375
Fix lint
richherrera Jul 15, 2024
cecce87
Merge branch 'fix-venmo-feature-merge' into eligibility-logic-request
richherrera Jul 15, 2024
3be4ecb
Add mising file
richherrera Jul 15, 2024
1ee3d2b
Add functionality on demo app
richherrera Jul 15, 2024
65ebc50
Merge branch 'venmo-feature' into eligibility-logic-request
richherrera Jul 16, 2024
cd016e3
PR feedback
richherrera Jul 16, 2024
c9f14ab
Change initializer
richherrera Jul 16, 2024
ee7e160
Fix tests
richherrera Jul 16, 2024
9a6dc5a
Fix coding key
richherrera Jul 16, 2024
54e53c0
Add EligibilityIntent docstrings and remove unnecessary intents
richherrera Jul 17, 2024
df51eb0
Fix UTs
richherrera Jul 17, 2024
8f253cf
Pass intent as parameter and mimic UI as others views
richherrera Jul 17, 2024
644df70
Change initializer
richherrera Jul 18, 2024
f9f2df3
Remove Recovered References directory
richherrera Jul 18, 2024
b422115
Lowercase supported payment methods
richherrera Jul 18, 2024
33d3d46
Use CurrentState enum instead of VenmoState
richherrera Jul 18, 2024
fb550e2
Remove VenmoState file
richherrera Jul 18, 2024
19239f9
Update Sources/CorePayments/Eligibility/EligibilityAPI.swift
richherrera Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
import SwiftUI
import CorePayments

struct VenmoPaymentView: View {

@State private var selectedIntent: EligibilityIntent = .capture
@StateObject var venmoPaymentsViewModel = VenmoPaymentsViewModel()

var body: some View {
Text("Hello, Venmo!")
VStack(spacing: 16) {
Text("Hello, Venmo!")
Picker("Intent", selection: $selectedIntent) {
Text("AUTHORIZE").tag(EligibilityIntent.authorize)
Text("CAPTURE").tag(EligibilityIntent.capture)
}
.pickerStyle(SegmentedPickerStyle())
ZStack {
Button("Check eligibility") {
Task {
do {
try await venmoPaymentsViewModel.getEligibility(selectedIntent)
} catch {
print("Error in getting payment token. \(error.localizedDescription)")
}
}
}
.buttonStyle(RoundedBlueButtonStyle())
if case .loading = venmoPaymentsViewModel.state {
CircularProgressView()
}
}
if case .success = venmoPaymentsViewModel.state {
if venmoPaymentsViewModel.isVenmoEligible {
Text("Venmo is eligible! 🥳")
} else {
Text("Venmo is not eligible! 🫤")
}
}
if case .error(let message) = venmoPaymentsViewModel.state {
Text(message)
}
}
.padding()
.background(
RoundedRectangle(cornerRadius: 10)
.stroke(.gray, lineWidth: 2)
.padding(5)
)
}
}

Expand Down
35 changes: 34 additions & 1 deletion Demo/Demo/ViewModels/VenmoPaymentsViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
import CorePayments
import Foundation

class VenmoPaymentsViewModel: ObservableObject { }
class VenmoPaymentsViewModel: ObservableObject {

let configManager = CoreConfigManager(domain: "Venmo Payments")

@Published var state: CurrentState = .idle

private var eligibilityResult: EligibilityResult?

var isVenmoEligible: Bool {
eligibilityResult?.isVenmoEligible ?? false
}

func getEligibility(_ intent: EligibilityIntent) async throws {
DispatchQueue.main.async {
self.state = .loading
}
do {
let config = try await configManager.getCoreConfig()
let eligibilityRequest = EligibilityRequest(currencyCode: "USD", intent: intent)
let eligibilityClient = EligibilityClient(config: config)
eligibilityResult = try? await eligibilityClient.check(eligibilityRequest)

DispatchQueue.main.async {
self.state = .success
}
} catch {
DispatchQueue.main.async {
self.state = .error(message: error.localizedDescription)
}
print("failed in updating setup token. \(error.localizedDescription)")
}
}
}
50 changes: 33 additions & 17 deletions PayPal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@
3BE7386D2B9A670400598F05 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3BE738662B9A593100598F05 /* PrivacyInfo.xcprivacy */; };
3D1763A22720722A00652E1C /* CardResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D1763A12720722A00652E1C /* CardResult.swift */; };
3DC42BA927187E8300B71645 /* ErrorResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC42BA827187E8300B71645 /* ErrorResponse.swift */; };
459633162C46BD63002008EF /* EligibilityIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 459633152C46BD63002008EF /* EligibilityIntent.swift */; };
459633182C46BD6F002008EF /* EligibilityResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 459633172C46BD6F002008EF /* EligibilityResponse.swift */; };
4596331A2C46BD7B002008EF /* SupportedPaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 459633192C46BD7B002008EF /* SupportedPaymentMethods.swift */; };
45B063B42C4035E200E743F2 /* EligibilityClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063B22C4035DB00E743F2 /* EligibilityClient.swift */; };
45B063B52C4035E500E743F2 /* EligibilityResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063B02C4034B700E743F2 /* EligibilityResult.swift */; };
45B063B62C4035EA00E743F2 /* EligibilityRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063AE2C40349300E743F2 /* EligibilityRequest.swift */; };
45B063B82C40440000E743F2 /* EligibilityVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063B72C40440000E743F2 /* EligibilityVariables.swift */; };
45B063BA2C40456F00E743F2 /* EligibilityAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063B92C40456F00E743F2 /* EligibilityAPI.swift */; };
45B063BD2C40545100E743F2 /* EligibilityClient_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063BC2C40545100E743F2 /* EligibilityClient_Tests.swift */; };
45B063BF2C40549000E743F2 /* EligibilityAPI_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063BE2C40549000E743F2 /* EligibilityAPI_Tests.swift */; };
45B063CA2C459F9900E743F2 /* MockEligibilityAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45B063C92C459F9900E743F2 /* MockEligibilityAPI.swift */; };
53A2A4E228A182AC0093441C /* NativeCheckoutProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A2A4E128A182AC0093441C /* NativeCheckoutProvider.swift */; };
62D3FB292C3DB5130046563B /* CorePayments.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80B9F85126B8750000D67843 /* CorePayments.framework */; platformFilter = ios; };
62D3FB4B2C3ED82D0046563B /* VenmoClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D3FB492C3ED82D0046563B /* VenmoClient.swift */; };
Expand Down Expand Up @@ -253,13 +257,17 @@
3D25238127344F330099E4EB /* NativeCheckoutStartable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NativeCheckoutStartable.swift; path = Sources/PayPalNativePayments/NativeCheckoutStartable.swift; sourceTree = SOURCE_ROOT; };
3D25238B273979170099E4EB /* MockNativeCheckoutProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockNativeCheckoutProvider.swift; sourceTree = "<group>"; };
3DC42BA827187E8300B71645 /* ErrorResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorResponse.swift; sourceTree = "<group>"; };
459633152C46BD63002008EF /* EligibilityIntent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EligibilityIntent.swift; sourceTree = "<group>"; };
459633172C46BD6F002008EF /* EligibilityResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EligibilityResponse.swift; sourceTree = "<group>"; };
459633192C46BD7B002008EF /* SupportedPaymentMethods.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupportedPaymentMethods.swift; sourceTree = "<group>"; };
45B063AE2C40349300E743F2 /* EligibilityRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityRequest.swift; sourceTree = "<group>"; };
45B063B02C4034B700E743F2 /* EligibilityResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityResult.swift; sourceTree = "<group>"; };
45B063B22C4035DB00E743F2 /* EligibilityClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityClient.swift; sourceTree = "<group>"; };
45B063B72C40440000E743F2 /* EligibilityVariables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityVariables.swift; sourceTree = "<group>"; };
45B063B92C40456F00E743F2 /* EligibilityAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityAPI.swift; sourceTree = "<group>"; };
45B063BC2C40545100E743F2 /* EligibilityClient_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityClient_Tests.swift; sourceTree = "<group>"; };
45B063BE2C40549000E743F2 /* EligibilityAPI_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EligibilityAPI_Tests.swift; sourceTree = "<group>"; };
45B063C92C459F9900E743F2 /* MockEligibilityAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockEligibilityAPI.swift; sourceTree = "<group>"; };
53A2A4E128A182AC0093441C /* NativeCheckoutProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeCheckoutProvider.swift; sourceTree = "<group>"; };
62D3FB132C3DB4D40046563B /* VenmoClient_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VenmoClient_Tests.swift; sourceTree = "<group>"; };
62D3FB2F2C3DB5130046563B /* VenmoPayments.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VenmoPayments.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -570,31 +578,17 @@
path = Models;
sourceTree = "<group>";
};
62D3FB122C3DB4B30046563B /* VenmoPaymentsTests */ = {
isa = PBXGroup;
children = (
62D3FB132C3DB4D40046563B /* VenmoClient_Tests.swift */,
);
path = VenmoPaymentsTests;
sourceTree = "<group>";
};
62D3FB4A2C3ED82D0046563B /* VenmoPayments */ = {
isa = PBXGroup;
children = (
62D3FB492C3ED82D0046563B /* VenmoClient.swift */,
);
name = VenmoPayments;
path = Sources/VenmoPayments;
sourceTree = "<group>";
};
45B063AD2C40346500E743F2 /* Eligibility */ = {
isa = PBXGroup;
children = (
45B063B92C40456F00E743F2 /* EligibilityAPI.swift */,
45B063B22C4035DB00E743F2 /* EligibilityClient.swift */,
459633152C46BD63002008EF /* EligibilityIntent.swift */,
45B063AE2C40349300E743F2 /* EligibilityRequest.swift */,
459633172C46BD6F002008EF /* EligibilityResponse.swift */,
45B063B02C4034B700E743F2 /* EligibilityResult.swift */,
45B063B72C40440000E743F2 /* EligibilityVariables.swift */,
459633192C46BD7B002008EF /* SupportedPaymentMethods.swift */,
);
path = Eligibility;
sourceTree = "<group>";
Expand All @@ -608,6 +602,23 @@
path = Eligibility;
sourceTree = "<group>";
};
62D3FB122C3DB4B30046563B /* VenmoPaymentsTests */ = {
isa = PBXGroup;
children = (
62D3FB132C3DB4D40046563B /* VenmoClient_Tests.swift */,
);
path = VenmoPaymentsTests;
sourceTree = "<group>";
};
62D3FB4A2C3ED82D0046563B /* VenmoPayments */ = {
isa = PBXGroup;
children = (
62D3FB492C3ED82D0046563B /* VenmoClient.swift */,
);
name = VenmoPayments;
path = Sources/VenmoPayments;
sourceTree = "<group>";
};
8036C1DE270F9BCF00C0F091 /* PaymentsCoreTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -650,6 +661,7 @@
isa = PBXGroup;
children = (
802EFBD72A9685DF00AB709D /* MockTrackingEventsAPI.swift */,
45B063C92C459F9900E743F2 /* MockEligibilityAPI.swift */,
);
path = Mocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -1482,6 +1494,7 @@
files = (
808EEA81291321FE001B6765 /* AnalyticsEventData_Tests.swift in Sources */,
8036C1E5270F9BE700C0F091 /* Environment_Tests.swift in Sources */,
45B063CA2C459F9900E743F2 /* MockEligibilityAPI.swift in Sources */,
80B96AAE2A980F6B00C62916 /* MockTrackingEventsAPI.swift in Sources */,
80FC261D29847AC7008EC841 /* HTTP_Tests.swift in Sources */,
45B063BD2C40545100E743F2 /* EligibilityClient_Tests.swift in Sources */,
Expand All @@ -1498,6 +1511,7 @@
buildActionMask = 2147483647;
files = (
E6022E802857C6BE008B0E27 /* GraphQLHTTPResponse.swift in Sources */,
459633182C46BD6F002008EF /* EligibilityResponse.swift in Sources */,
80E643832A1EBBD2008FD705 /* HTTPResponse.swift in Sources */,
807C5E6929102D9800ECECD8 /* AnalyticsEventData.swift in Sources */,
80E237DF2A84434B00FF18CA /* HTTPRequest.swift in Sources */,
Expand All @@ -1514,6 +1528,7 @@
80E2FDC12A83535A0045593D /* TrackingEventsAPI.swift in Sources */,
BEA100F226EFA7DE0036A6A5 /* Environment.swift in Sources */,
BEA100F026EFA7C20036A6A5 /* NetworkingClientError.swift in Sources */,
459633162C46BD63002008EF /* EligibilityIntent.swift in Sources */,
804E628629380B04004B9FEF /* AnalyticsService.swift in Sources */,
45B063BA2C40456F00E743F2 /* EligibilityAPI.swift in Sources */,
BC04837427B2FC7300FA7B46 /* URLSession+URLSessionProtocol.swift in Sources */,
Expand All @@ -1524,6 +1539,7 @@
804E62822937EBCE004B9FEF /* HTTP.swift in Sources */,
BC04836F27B2FB3600FA7B46 /* URLSessionProtocol.swift in Sources */,
065A4DBC26FCD8090007014A /* CoreSDKError.swift in Sources */,
4596331A2C46BD7B002008EF /* SupportedPaymentMethods.swift in Sources */,
BEA100E726EF9EDA0036A6A5 /* NetworkingClient.swift in Sources */,
807BF58F2A2A5D19002F32B3 /* HTTPResponseParser.swift in Sources */,
807D56AE2A869064009E591D /* GraphQLRequest.swift in Sources */,
Expand Down
65 changes: 63 additions & 2 deletions Sources/CorePayments/Eligibility/EligibilityAPI.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,77 @@
import Foundation

final class EligibilityAPI {
/// API that return merchant's eligibility for different payment methods: Venmo, PayPal, PayPal Credit, Pay Later & credit card
class EligibilityAPI {

// MARK: - Private Propertires

private let coreConfig: CoreConfig
private let networkingClient: NetworkingClient

// MARK: - Initializer
// MARK: - Initializers

/// Initialize the eligibility API to check for payment methods eligibility
/// - Parameter coreConfig: configuration object
init(coreConfig: CoreConfig) {
self.coreConfig = coreConfig
self.networkingClient = NetworkingClient(coreConfig: coreConfig)
}

/// Exposed for injecting MockNetworkingClient in tests
init(coreConfig: CoreConfig, networkingClient: NetworkingClient) {
self.coreConfig = coreConfig
self.networkingClient = networkingClient
}

// MARK: - Internal Methods

/// Checks merchants eligibility for different payment methods.
/// - Returns: An `EligibilityResponse` containing the result of the eligibility check.
richherrera marked this conversation as resolved.
Show resolved Hide resolved
/// - Throws: An `Error` describing the failure.

func check(_ eligibilityRequest: EligibilityRequest) async throws -> EligibilityResponse {
let variables = EligibilityVariables(eligibilityRequest: eligibilityRequest, clientID: coreConfig.clientID)
let graphQLRequest = GraphQLRequest(query: Self.rawQuery, variables: variables)
let httpResponse = try await networkingClient.fetch(request: graphQLRequest)

return try HTTPResponseParser().parseGraphQL(httpResponse, as: EligibilityResponse.self)
}
}

extension EligibilityAPI {

static let rawQuery = """
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really need this to be in an extension here. Was there a particular reason for using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to put the query in an extension to make the code more readable. I based it on this implementation where the query is in the same method, which makes the method much larger. Basically, it's to separate(ish) responsibilities

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also throw it in a private method under check if we want to separate it but move it out of the extension

query getEligibility(
$clientId: String!,
$intent: FundingEligibilityIntent!,
$currency: SupportedCountryCurrencies!,
$enableFunding: [SupportedPaymentMethodsType]
){
fundingEligibility(
clientId: $clientId,
intent: $intent
currency: $currency,
enableFunding: $enableFunding){
venmo{
eligible
reasons
}
card{
eligible
}
paypal{
eligible
reasons
}
paylater{
eligible
reasons
}
credit{
eligible
reasons
}
}
}
"""
}
31 changes: 29 additions & 2 deletions Sources/CorePayments/Eligibility/EligibilityClient.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import Foundation

/// The `EligibilityClient` class provides methods to check eligibility status based on provided requests.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Nice docstrings

public final class EligibilityClient {

private let api: EligibilityAPI
private let config: CoreConfig

// MARK: - Initializers

/// Initializes a new instance of `EligibilityClient`.
/// - Parameter config: The core configuration needed for the client.
public init(config: CoreConfig) {
self.config = config
self.api = EligibilityAPI(coreConfig: config)
}

/// Exposed for injecting MockEligibilityAPI in tests
init(config: CoreConfig, api: EligibilityAPI) {
self.config = config
self.api = api
}

// MARK: - Public Methods

/// Checks the eligibility based on the provided `EligibilityRequest`.
///
/// This method calls the `EligibilityAPI` to perform the check and converts the response to `EligibilityResult`.
///
/// - Parameter eligibilityRequest: The eligibility request containing the necessary data to perform the check.
/// - Throws: An error if the network request or parsing fails.
/// - Returns: An `EligibilityResult` containing the result of the eligibility check.
public func check(_ eligibilityRequest: EligibilityRequest) async throws -> EligibilityResult {
// TODO: - Add logic
.init(isVenmoEligible: false)
try await api.check(eligibilityRequest).asResult
}
}
11 changes: 11 additions & 0 deletions Sources/CorePayments/Eligibility/EligibilityIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

Copy link
Contributor Author

@richherrera richherrera Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this enum based on the logic that was previously removed:

/// Enum representing the possible intents for eligibility.
public enum EligibilityIntent: String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I wonder if we only support CAPTURE and AUTHORIZE. Per these PP docs, these are the only 2 you can create an orderID with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be OK to just start with those 2. Also needs a docstring since public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 docs says SALE and AUTHORIZE, thanks for your feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, I also changed cases to lowercase to be more Swifty: 54e53c0


/// Represents the intent to capture a payment.
case capture = "CAPTURE"

/// Represents the intent to authorize a payment.
case authorize = "AUTHORIZE"
}
24 changes: 18 additions & 6 deletions Sources/CorePayments/Eligibility/EligibilityRequest.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import Foundation

/// The `EligibilityRequest` structure includes the necessary parameters to make an eligibility check request.
public struct EligibilityRequest {

let intent: String
let currency: String
let enableFunding: [String]
// MARK: - Internal Properties

/// The currency code for the eligibility request.
let currencyCode: String

/// The intent of the eligibility request.
let intent: EligibilityIntent

/// An array of supported payment methods for the request. Defaults to `[.VENMO]`.
let enableFunding: [SupportedPaymentMethodsType]

// MARK: - Initializer

public init(intent: String, currency: String, enableFunding: [String]) {
/// Creates an instance of a eligibility request
/// - Parameters:
/// - currencyCode: The currency code for the eligibility request.
/// - intent: The intent of the eligibility request.
public init(currencyCode: String, intent: EligibilityIntent) {
self.currencyCode = currencyCode
self.intent = intent
self.currency = currency
self.enableFunding = enableFunding
self.enableFunding = [.venmo]
}
}
Loading
Loading