Skip to content

Card Form in PayPalWebPayments #321

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

Open
wants to merge 11 commits into
base: bcdc-feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

# PayPal iOS SDK Release Notes

## unreleased
* PaymentButtons
* Add `CardButton` to be used for PayPal guest checkout using card funding option
* PaymentButtons
* Add `card` option in `PayPalWebChecoutFundingSource` for web card field option

## 2.0.0 (2025-03-18)
* Breaking Changes
* PayPalNativePayments
Expand Down
13 changes: 12 additions & 1 deletion Demo/Demo/Extensions/PaymentButtonEnums+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ extension PayPalCreditButton.Color {
}
}

extension CardButton.Color {
Copy link
Collaborator

Choose a reason for hiding this comment

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

q: Are we able to use CaseIterable to autogenerate this code? link: docs.swift.org

Copy link
Collaborator Author

@KunJeongPark KunJeongPark Apr 7, 2025

Choose a reason for hiding this comment

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

The extensions in the demo app were done that way because those enums are declared in the SDK and we can't add CaseIterable conformance from outside the module. This iteration is not something the user would do, but kind of specific to our demo app to showcase all possible button appearances


public static var allCases: [CardButton.Color] {
[.black, .white]
}

static func allCasesAsString() -> [String] {
Self.allCases.map { $0.rawValue }
}
}

extension PaymentButtonEdges {

public static var allCases: [PaymentButtonEdges] {
Expand All @@ -58,7 +69,7 @@ extension PaymentButtonSize {
extension PaymentButtonFundingSource {

public static var allCases: [PaymentButtonFundingSource] {
[.payPal, .payLater, .credit]
[.payPal, .payLater, .credit, .card]
}

static func allCasesAsString() -> [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct PayPalWebButtonsView: View {
Text("PayPal").tag(PayPalWebCheckoutFundingSource.paypal)
Text("PayPal Credit").tag(PayPalWebCheckoutFundingSource.paypalCredit)
Text("Pay Later").tag(PayPalWebCheckoutFundingSource.paylater)
Text("Card").tag(PayPalWebCheckoutFundingSource.card)
}
.pickerStyle(SegmentedPickerStyle())
ZStack {
Expand All @@ -38,6 +39,10 @@ struct PayPalWebButtonsView: View {
PayPalButton.Representable(color: .blue, size: .full) {
payPalWebViewModel.paymentButtonTapped(funding: .paypal)
}
case .card:
CardButton.Representable(color: .black, size: .full) {
payPalWebViewModel.paymentButtonTapped(funding: .card)
}
}
if payPalWebViewModel.state.approveResultResponse == .loading &&
payPalWebViewModel.checkoutResult == nil &&
Expand Down
11 changes: 11 additions & 0 deletions Demo/Demo/SwiftUIComponents/SwiftUIPaymentButtonDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ struct SwiftUIPaymentButtonDemo: View {
size: selectedSize
)
.id(buttonID)

case .card:
CardButton.Representable(
color: CardButton.Color.allCases[colorsIndex],
edges: selectedEdge,
size: selectedSize
)
.id(buttonID)
}
}
.padding()
Expand All @@ -136,6 +144,9 @@ struct SwiftUIPaymentButtonDemo: View {

case .credit:
return PayPalCreditButton.Color.allCasesAsString()

case .card:
return CardButton.Color.allCasesAsString()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PayPal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Pod::Spec.new do |s|
end

s.subspec "PayPalWebPayments" do |s|
s.source_files = "Sources/PayPalWebPayments/*.swift"
s.source_files = "Sources/PayPalWebPayments/**/*.swift"
s.dependency "PayPal/CorePayments"
s.resource_bundle = { "PayPalWebPayments_PrivacyInfo" => "Sources/PayPalWebPayments/PrivacyInfo.xcprivacy" }
end
Expand Down
101 changes: 80 additions & 21 deletions PayPal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
3B22E8B82A841AEA00962E34 /* CardVaultResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B22E8B72A841AEA00962E34 /* CardVaultResult.swift */; };
3B29C3972B9148F70077741D /* PayPalVaultRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B29C3962B9148F70077741D /* PayPalVaultRequest.swift */; };
3B3C511E2B2395B5009125FE /* PayPalVaultResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3C511D2B2395B5009125FE /* PayPalVaultResult.swift */; };
3B7387212D919B5A007354C2 /* ClientConfigResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B7387202D919B5A007354C2 /* ClientConfigResponse.swift */; };
3B783DC32B7A69C2004623DB /* FakeUpdateSetupTokenResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B783DC22B7A69C2004623DB /* FakeUpdateSetupTokenResponse.swift */; };
3B79E4F72A8503CA00C01D06 /* UpdateVaultVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B79E4F62A8503C900C01D06 /* UpdateVaultVariables.swift */; };
3B80D50C2A27979000D2EAC4 /* FailingJSONEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B80D50B2A27979000D2EAC4 /* FailingJSONEncoder.swift */; };
3B8F84842D92F95500A151AC /* CardButton_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B8F84832D92F94600A151AC /* CardButton_Tests.swift */; };
3B8F84862D93319800A151AC /* UpdateClientConfigAP_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B8F84852D93318D00A151AC /* UpdateClientConfigAP_Tests.swift */; };
3B8F848C2D93380B00A151AC /* TestShared.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80E743F8270E40CE00BACECA /* TestShared.framework */; };
3B8F84922D933FBA00A151AC /* MockUpdateClientConfigAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B8F84912D933FAE00A151AC /* MockUpdateClientConfigAPI.swift */; };
3BD014C82D8B4D60005565FE /* CardButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD014C72D8B4D60005565FE /* CardButton.swift */; };
3BD014CB2D8DE711005565FE /* UpdateClientConfigAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD014CA2D8DE701005565FE /* UpdateClientConfigAPI.swift */; };
3BD014CD2D8DF2B8005565FE /* UpdateClientConfigVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD014CC2D8DF2AF005565FE /* UpdateClientConfigVariables.swift */; };
3BD82DBB2A835AF900CBE764 /* UpdateSetupTokenResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD82DBA2A835AF900CBE764 /* UpdateSetupTokenResponse.swift */; };
3BDB34942A80CE6E008100D7 /* CardVaultRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BDB34932A80CE6E008100D7 /* CardVaultRequest.swift */; };
3BE738682B9A66D800598F05 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3BE738622B9A482800598F05 /* PrivacyInfo.xcprivacy */; };
Expand Down Expand Up @@ -133,6 +141,20 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
3B8F84892D9337FF00A151AC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = BCD5C46727E9200800B074D5;
remoteInfo = PayPalWebPayments;
};
3B8F848E2D93380B00A151AC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 80E743F7270E40CE00BACECA;
remoteInfo = TestShared;
};
8034A9E826B875C90055AF13 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
Expand All @@ -154,13 +176,6 @@
remoteGlobalIDString = BCF735C227D1583200A52E03;
remoteInfo = PayPalDataCollector;
};
BCD5C49627E9208000B074D5 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = BCD5C46727E9200800B074D5;
remoteInfo = PayPalWebCheckout;
};
BCFAC72027ED059C00C3AF00 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
Expand All @@ -183,9 +198,16 @@
3B22E8B72A841AEA00962E34 /* CardVaultResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardVaultResult.swift; sourceTree = "<group>"; };
3B29C3962B9148F70077741D /* PayPalVaultRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalVaultRequest.swift; sourceTree = "<group>"; };
3B3C511D2B2395B5009125FE /* PayPalVaultResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalVaultResult.swift; sourceTree = "<group>"; };
3B7387202D919B5A007354C2 /* ClientConfigResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientConfigResponse.swift; sourceTree = "<group>"; };
3B783DC22B7A69C2004623DB /* FakeUpdateSetupTokenResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeUpdateSetupTokenResponse.swift; sourceTree = "<group>"; };
3B79E4F62A8503C900C01D06 /* UpdateVaultVariables.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateVaultVariables.swift; sourceTree = "<group>"; };
3B80D50B2A27979000D2EAC4 /* FailingJSONEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FailingJSONEncoder.swift; sourceTree = "<group>"; };
3B8F84832D92F94600A151AC /* CardButton_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardButton_Tests.swift; sourceTree = "<group>"; };
3B8F84852D93318D00A151AC /* UpdateClientConfigAP_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateClientConfigAP_Tests.swift; sourceTree = "<group>"; };
3B8F84912D933FAE00A151AC /* MockUpdateClientConfigAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUpdateClientConfigAPI.swift; sourceTree = "<group>"; };
3BD014C72D8B4D60005565FE /* CardButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardButton.swift; sourceTree = "<group>"; };
3BD014CA2D8DE701005565FE /* UpdateClientConfigAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateClientConfigAPI.swift; sourceTree = "<group>"; };
3BD014CC2D8DF2AF005565FE /* UpdateClientConfigVariables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateClientConfigVariables.swift; sourceTree = "<group>"; };
3BD82DBA2A835AF900CBE764 /* UpdateSetupTokenResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateSetupTokenResponse.swift; sourceTree = "<group>"; };
3BDB34932A80CE6E008100D7 /* CardVaultRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardVaultRequest.swift; sourceTree = "<group>"; };
3BE738622B9A482800598F05 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
Expand Down Expand Up @@ -353,6 +375,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 0;
files = (
3B8F848C2D93380B00A151AC /* TestShared.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -444,6 +467,24 @@
path = Models;
sourceTree = "<group>";
};
3B8F84902D933FA700A151AC /* Mocks */ = {
isa = PBXGroup;
children = (
3B8F84912D933FAE00A151AC /* MockUpdateClientConfigAPI.swift */,
);
path = Mocks;
sourceTree = "<group>";
};
3BD014C92D8DE6EF005565FE /* APIRequests */ = {
isa = PBXGroup;
children = (
3B7387202D919B5A007354C2 /* ClientConfigResponse.swift */,
3BD014CC2D8DF2AF005565FE /* UpdateClientConfigVariables.swift */,
3BD014CA2D8DE701005565FE /* UpdateClientConfigAPI.swift */,
);
path = APIRequests;
sourceTree = "<group>";
};
8036C1DE270F9BCF00C0F091 /* PaymentsCoreTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -559,20 +600,14 @@
BCE8A7F027EA52BF00AC301B /* PayPalWebPaymentsTests */ = {
isa = PBXGroup;
children = (
BCE8A7F127EA52EB00AC301B /* Mocks */,
3B8F84902D933FA700A151AC /* Mocks */,
3B8F84852D93318D00A151AC /* UpdateClientConfigAP_Tests.swift */,
BCE8A7FA27EA5B1D00AC301B /* Environment+PayPalWebCheckout_Tests.swift */,
BCE8A7F827EA555800AC301B /* PayPalWebCheckoutClient_Tests.swift */,
);
path = PayPalWebPaymentsTests;
sourceTree = "<group>";
};
BCE8A7F127EA52EB00AC301B /* Mocks */ = {
isa = PBXGroup;
children = (
);
path = Mocks;
sourceTree = "<group>";
};
BCF735C127D157CD00A52E03 /* FraudProtection */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -605,6 +640,7 @@
isa = PBXGroup;
children = (
BE00B79D2742F9F000758C63 /* Assets.xcassets */,
3BD014C72D8B4D60005565FE /* CardButton.swift */,
BEDB7FE32788AB8E00CEA554 /* Coordinator.swift */,
BE00B7AA2743FD9F00758C63 /* PaymentButton.swift */,
BE9F36DE274859A000AFC7DA /* PaymentButtonColor.swift */,
Expand All @@ -626,6 +662,7 @@
BCFAC72227ED05D900C3AF00 /* PaymentButtonsTests */ = {
isa = PBXGroup;
children = (
3B8F84832D92F94600A151AC /* CardButton_Tests.swift */,
BEF3FF1627AC5DF3006B4B69 /* Coordinator_Tests.swift */,
BE00B7AC27444FE900758C63 /* PayPalButton_Tests.swift */,
BE9F36E3275520E700AFC7DA /* PayPalCreditButton_Tests.swift */,
Expand All @@ -637,6 +674,7 @@
BE4F784227EB627100FF4C0E /* PayPalWebPayments */ = {
isa = PBXGroup;
children = (
3BD014C92D8DE6EF005565FE /* APIRequests */,
BE4F784327EB629100FF4C0E /* Environment+PayPalWebCheckout.swift */,
BE4F784627EB629100FF4C0E /* PayPalWebCheckoutClient.swift */,
BE4F784427EB629100FF4C0E /* PayPalError.swift */,
Expand Down Expand Up @@ -883,7 +921,8 @@
buildRules = (
);
dependencies = (
BCD5C49727E9208000B074D5 /* PBXTargetDependency */,
3B8F848A2D9337FF00A151AC /* PBXTargetDependency */,
3B8F848F2D93380B00A151AC /* PBXTargetDependency */,
);
name = PayPalWebPaymentsTests;
productName = PayPalTests;
Expand Down Expand Up @@ -1242,8 +1281,11 @@
BE4F785327EB656400FF4C0E /* Environment+PayPalWebCheckout.swift in Sources */,
BE4F785427EB656400FF4C0E /* PayPalWebCheckoutClient.swift in Sources */,
BE4F785527EB656400FF4C0E /* PayPalError.swift in Sources */,
3B7387212D919B5A007354C2 /* ClientConfigResponse.swift in Sources */,
3BD014CD2D8DF2B8005565FE /* UpdateClientConfigVariables.swift in Sources */,
BE4F785727EB656400FF4C0E /* PayPalWebCheckoutRequest.swift in Sources */,
BE4F785827EB656400FF4C0E /* PayPalWebCheckoutResult.swift in Sources */,
3BD014CB2D8DE711005565FE /* UpdateClientConfigAPI.swift in Sources */,
CB51FF7227FCB947001A97F5 /* PayPalWebCheckoutFundingSource.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -1253,6 +1295,8 @@
buildActionMask = 0;
files = (
BCE8A7FB27EA5B1D00AC301B /* Environment+PayPalWebCheckout_Tests.swift in Sources */,
3B8F84862D93319800A151AC /* UpdateClientConfigAP_Tests.swift in Sources */,
3B8F84922D933FBA00A151AC /* MockUpdateClientConfigAPI.swift in Sources */,
BCE8A7F927EA555800AC301B /* PayPalWebCheckoutClient_Tests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1297,6 +1341,7 @@
BCFAC71F27ED04C800C3AF00 /* Coordinator.swift in Sources */,
BCFAC71C27ED04C000C3AF00 /* PaymentButton.swift in Sources */,
CB1A47F22820AFED00BD8184 /* PayPalPayLaterButton.swift in Sources */,
3BD014C82D8B4D60005565FE /* CardButton.swift in Sources */,
CB1A47F42820BA5D00BD8184 /* PaymentButtonEdges.swift in Sources */,
BCFAC71A27ED04AC00C3AF00 /* PaymentButtonColor.swift in Sources */,
);
Expand All @@ -1307,6 +1352,7 @@
buildActionMask = 0;
files = (
BCFAC70E27ED043100C3AF00 /* PayPalButton_Tests.swift in Sources */,
3B8F84842D92F95500A151AC /* CardButton_Tests.swift in Sources */,
BCFAC70F27ED043100C3AF00 /* Coordinator_Tests.swift in Sources */,
CB22C018291049500097E592 /* PayPalPayLaterButton_Tests.swift in Sources */,
BCFAC71327ED043100C3AF00 /* PayPalCreditButton_Tests.swift in Sources */,
Expand All @@ -1316,6 +1362,24 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
3B8F848A2D9337FF00A151AC /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilters = (
driverkit,
ios,
macos,
tvos,
watchos,
xros,
);
target = BCD5C46727E9200800B074D5 /* PayPalWebPayments */;
targetProxy = 3B8F84892D9337FF00A151AC /* PBXContainerItemProxy */;
};
3B8F848F2D93380B00A151AC /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 80E743F7270E40CE00BACECA /* TestShared */;
targetProxy = 3B8F848E2D93380B00A151AC /* PBXContainerItemProxy */;
};
8034A9E926B875C90055AF13 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 80B9F85026B8750000D67843 /* CorePayments */;
Expand All @@ -1331,11 +1395,6 @@
target = BCF735C227D1583200A52E03 /* FraudProtection */;
targetProxy = BC9C18DF27D2B1850019B541 /* PBXContainerItemProxy */;
};
BCD5C49727E9208000B074D5 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = BCD5C46727E9200800B074D5 /* PayPalWebPayments */;
targetProxy = BCD5C49627E9208000B074D5 /* PBXContainerItemProxy */;
};
BCFAC72127ED059C00C3AF00 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = BCFAC6EB27ED042500C3AF00 /* PaymentButtons */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CorePayments
/// This class coordinates networking logic for communicating with the /graphql?UpdateVaultSetupToken API.
class VaultPaymentTokensAPI {

// MARK: - Private Propertires
// MARK: - Private Properties

private let coreConfig: CoreConfig
private let networkingClient: NetworkingClient
Expand Down
1 change: 1 addition & 0 deletions Sources/CorePayments/Networking/Enums/HTTPHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public enum HTTPHeader: String {
case authorization = "Authorization"
case contentType = "Content-Type"
case origin = "Origin"
case payPalClientContext = "paypal-client-context"
}
22 changes: 22 additions & 0 deletions Sources/CorePayments/Networking/HTTPResponseParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,25 @@ public class HTTPResponseParser {
}
}
}

extension HTTPResponseParser {

// to extract correlationId from GraphQL response
public func parseGraphQLDictionary(_ httpResponse: HTTPResponse) throws -> [String: Any] {

guard httpResponse.status == 200 else {
throw NetworkingError.urlSessionError
}

guard let body = httpResponse.body else {
throw NetworkingError.noResponseDataError
}

let jsonObject = try JSONSerialization.jsonObject(with: body, options: [])
guard let topLevel = jsonObject as? [String: Any] else {
throw NetworkingError.invalidURLResponseError
}

return topLevel
}
}
Loading