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

[V7] Add Encodable protocol for PayPal Vault #1492

Merged
merged 55 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d53299c
Add file with paypal request properties
richherrera Dec 30, 2024
cf7ad1e
Add var to BTConfiguration extension
richherrera Dec 30, 2024
964d7e8
Add country iso code var
richherrera Dec 30, 2024
7460d9d
Add checkout properties to POST body model
richherrera Dec 30, 2024
0a3dbf4
Disable nesting lint
richherrera Jan 2, 2025
f5952e6
Address some lints
richherrera Jan 2, 2025
3168bf5
Add dot
richherrera Jan 2, 2025
623c681
Rename struct
richherrera Jan 2, 2025
8006e18
Add Encodable protocol to BTPostalAddress class
richherrera Jan 3, 2025
d1c1cd1
Add Encodable protocol to BTPayPalBillingCycle struct
richherrera Jan 3, 2025
14390fd
Add Encodable protocol to BTPayPalBillingPricing struct
richherrera Jan 3, 2025
06fd294
Add Encodable protocol to BTPayPalRecurringBillingDetails struct
richherrera Jan 3, 2025
6f0daad
Add Encodable protocol to BTPayPalRecurringBillingPlanType enum
richherrera Jan 3, 2025
428b0a4
Add PayPalVaultPOSTBody file
richherrera Jan 3, 2025
2b072da
Add encodable properties
richherrera Jan 3, 2025
09d964d
Add Encodable protocol to BTPayPalLineItem class
richherrera Jan 6, 2025
c7e226e
Merge branch 'paypal-checkout-encodable' into paypal-vault-encodable
richherrera Jan 6, 2025
9543469
Use encodable for BTLineItems
richherrera Jan 6, 2025
27c0a44
Add error to catch encodable exception
richherrera Jan 6, 2025
4a6e7d8
Use encoded objects
richherrera Jan 6, 2025
42af3f7
Use Configuration.isPayPalEnabled instead of json format
richherrera Jan 6, 2025
2200e5c
Add PayPalExperienceProfile as a shared object to be use for Checkout…
richherrera Jan 6, 2025
1553b22
Add PayPalRequest protocol, BTPayPalRequest conforms PayPalRequest
richherrera Jan 9, 2025
f9c90ec
BTPayPalCheckoutRequest conforms PayPalRequest
richherrera Jan 9, 2025
abe2c7e
Move lineItems parameters on init
richherrera Jan 9, 2025
b0cea93
BTPayPalVaultRequest conforms PayPalRequest
richherrera Jan 9, 2025
4a3b49c
Update BTPayPalRequest UTs
richherrera Jan 9, 2025
49886c7
Update BTPayPalClient to use an interface instead of concrete class
richherrera Jan 9, 2025
47727f4
Merge branch 'v7' into paypal-checkout-encodable
richherrera Jan 9, 2025
3c1701e
Disable cyclomatic_complexity lint
richherrera Jan 9, 2025
b6ce34b
Disable function_body_length lint
richherrera Jan 9, 2025
50c23ac
Merge branch 'paypal-checkout-encodable' into paypal-vault-encodable
richherrera Jan 9, 2025
8e12bf8
Address PR comments
richherrera Jan 9, 2025
8b18aeb
Remove parameters method
richherrera Jan 9, 2025
b903ba2
Remove BTPayPalRequest class
richherrera Jan 9, 2025
44d61f4
Add PayPalConstanst enum
richherrera Jan 9, 2025
7f0a207
Remove unnecessary error
richherrera Jan 9, 2025
39ca19f
Move encoded method
richherrera Jan 9, 2025
169ff3a
Update UTs
richherrera Jan 9, 2025
d6284ec
Move BTPayPalRequest UTs to BTPayPalCheckout and BTPayPalVault requests
richherrera Jan 10, 2025
7601a15
Delete BTPayPalRequest UTs
richherrera Jan 10, 2025
e446f03
Use if let syntax
richherrera Jan 10, 2025
ac6f13e
Address PR comments
richherrera Jan 10, 2025
e478437
Remove BTLineItems custom encode method
richherrera Jan 13, 2025
6dfb488
Revert unnecessary changes
richherrera Jan 13, 2025
5b86155
Merge branch 'paypal-checkout-encodable' into paypal-vault-encodable
richherrera Jan 13, 2025
f90356b
Rename PayPalRequest protocol to BTPayPalRequest
richherrera Jan 13, 2025
df8eba1
Remove unnecessary parameters methods
richherrera Jan 13, 2025
3fa9a0d
Remove unnecessary parameters methods
richherrera Jan 13, 2025
f3ccfe4
Add quotation marks
richherrera Jan 21, 2025
876599d
Add docstrings and move the enums to their own file.
richherrera Jan 21, 2025
e56a718
Merge branch 'paypal-checkout-encodable' into paypal-vault-encodable
richherrera Jan 21, 2025
09357ff
Address PR comments
richherrera Jan 21, 2025
5cf34f5
Merge branch 'v7' into paypal-vault-encodable
richherrera Jan 21, 2025
362f9bb
Update paypalrequest property
richherrera Jan 21, 2025
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
24 changes: 20 additions & 4 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
427F32E025D1D62D00435294 /* BTPayPalClient_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 427F32DF25D1D62D00435294 /* BTPayPalClient_Tests.swift */; };
428F48E42624C9B700EC8DB4 /* BTVenmoAppSwitchRedirectURL_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 428F48E32624C9B700EC8DB4 /* BTVenmoAppSwitchRedirectURL_Tests.swift */; };
428F976626727333001042E1 /* BTMockOpenURLContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 428F976526727333001042E1 /* BTMockOpenURLContext.m */; };
42FC218B25CDE0290047C49A /* BTPayPalRequest_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42FC218A25CDE0290047C49A /* BTPayPalRequest_Tests.swift */; };
42FC237125CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42FC237025CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift */; };
45227FC52C330FDE00A15018 /* MockURLSessionTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45227FC32C330FDE00A15018 /* MockURLSessionTask.swift */; };
45227FC72C33104100A15018 /* MockBTHTTPNetworkTiming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45227FC62C33104100A15018 /* MockBTHTTPNetworkTiming.swift */; };
Expand All @@ -44,6 +43,9 @@
458570782C34A699009CEF7A /* ConfigurationLoader_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 458570772C34A699009CEF7A /* ConfigurationLoader_Tests.swift */; };
4585707A2C34B1E1009CEF7A /* MockClientAuthorization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 458570792C34B1E1009CEF7A /* MockClientAuthorization.swift */; };
4585707C2C34B7B5009CEF7A /* MockConfigurationLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4585707B2C34B7B5009CEF7A /* MockConfigurationLoader.swift */; };
45E8CE4C2D1F29BA00D7A2DC /* PayPalCheckoutPOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E8CE4B2D1F29BA00D7A2DC /* PayPalCheckoutPOSTBody.swift */; };
45E8CE4E2D28611700D7A2DC /* PayPalVaultPOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E8CE4D2D28611700D7A2DC /* PayPalVaultPOSTBody.swift */; };
45E8CE502D2C773600D7A2DC /* PayPalExperienceProfilePOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E8CE4F2D2C772000D7A2DC /* PayPalExperienceProfilePOSTBody.swift */; };
45E8CE522D2C920000D7A2DC /* LocalPaymentAccountsPOSTBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E8CE512D2C91F000D7A2DC /* LocalPaymentAccountsPOSTBody.swift */; };
45EFC3972C2DBF32005E7F5B /* ConfigurationLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45EFC3962C2DBF32005E7F5B /* ConfigurationLoader.swift */; };
460C0C220F594AE8EE205E57 /* Pods_Tests_BraintreeCoreTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9239C9FE850C3587DE61A3A2 /* Pods_Tests_BraintreeCoreTests.framework */; };
Expand Down Expand Up @@ -716,7 +718,6 @@
42F2FF2E2333D2B20083CA10 /* BTAuthenticationInsight_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTAuthenticationInsight_Tests.swift; sourceTree = "<group>"; };
42F75E5824D46DA2007DC5E7 /* BTThreeDSecureLookup_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureLookup_Tests.swift; sourceTree = "<group>"; };
42F75E5A24D48138007DC5E7 /* BTThreeDSecureClient_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureClient_Tests.swift; sourceTree = "<group>"; };
42FC218A25CDE0290047C49A /* BTPayPalRequest_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalRequest_Tests.swift; sourceTree = "<group>"; };
42FC237025CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPayPalCheckoutRequest_Tests.swift; sourceTree = "<group>"; };
45227FC32C330FDE00A15018 /* MockURLSessionTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLSessionTask.swift; sourceTree = "<group>"; };
45227FC62C33104100A15018 /* MockBTHTTPNetworkTiming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBTHTTPNetworkTiming.swift; sourceTree = "<group>"; };
Expand All @@ -726,6 +727,9 @@
458570772C34A699009CEF7A /* ConfigurationLoader_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationLoader_Tests.swift; sourceTree = "<group>"; };
458570792C34B1E1009CEF7A /* MockClientAuthorization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockClientAuthorization.swift; sourceTree = "<group>"; };
4585707B2C34B7B5009CEF7A /* MockConfigurationLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockConfigurationLoader.swift; sourceTree = "<group>"; };
45E8CE4B2D1F29BA00D7A2DC /* PayPalCheckoutPOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalCheckoutPOSTBody.swift; sourceTree = "<group>"; };
45E8CE4D2D28611700D7A2DC /* PayPalVaultPOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalVaultPOSTBody.swift; sourceTree = "<group>"; };
45E8CE4F2D2C772000D7A2DC /* PayPalExperienceProfilePOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalExperienceProfilePOSTBody.swift; sourceTree = "<group>"; };
45E8CE512D2C91F000D7A2DC /* LocalPaymentAccountsPOSTBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalPaymentAccountsPOSTBody.swift; sourceTree = "<group>"; };
45EFC3962C2DBF32005E7F5B /* ConfigurationLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationLoader.swift; sourceTree = "<group>"; };
463DED22C0F426A474E6D7E2 /* Pods-Tests-BraintreeCoreTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests-BraintreeCoreTests.release.xcconfig"; path = "Target Support Files/Pods-Tests-BraintreeCoreTests/Pods-Tests-BraintreeCoreTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1300,6 +1304,7 @@
BE349112294B798300D2CF68 /* BTPayPalRequest.swift */,
BE6BC22D2BA9CFFC00C3E321 /* BTPayPalReturnURL.swift */,
BE349110294B77E100D2CF68 /* BTPayPalVaultRequest.swift */,
45E8CE4A2D1F291400D7A2DC /* Models */,
62A659A32B98CB23008DFD67 /* PrivacyInfo.xcprivacy */,
807D22F32C29ADA8009FFEA4 /* RecurringBillingMetadata */,
62B811872CC002470024A688 /* BTPayPalPhoneNumber.swift */,
Expand All @@ -1316,6 +1321,16 @@
path = Models;
sourceTree = "<group>";
};
45E8CE4A2D1F291400D7A2DC /* Models */ = {
isa = PBXGroup;
children = (
45E8CE4B2D1F29BA00D7A2DC /* PayPalCheckoutPOSTBody.swift */,
45E8CE4D2D28611700D7A2DC /* PayPalVaultPOSTBody.swift */,
45E8CE4F2D2C772000D7A2DC /* PayPalExperienceProfilePOSTBody.swift */,
);
path = Models;
sourceTree = "<group>";
};
570B93AE285397D20041BAFE /* BraintreeCore */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1905,7 +1920,6 @@
42FC237025CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift */,
427F32DF25D1D62D00435294 /* BTPayPalClient_Tests.swift */,
BECB10C52B5999EE008D398E /* BTPayPalLineItem_Tests.swift */,
42FC218A25CDE0290047C49A /* BTPayPalRequest_Tests.swift */,
BEBA590E2BB1B5B9005FA8A2 /* BTPayPalReturnURL_Tests.swift */,
427F328F25D1A7B900435294 /* BTPayPalVaultRequest_Tests.swift */,
A9E5C1E424FD665D00EE691F /* Info.plist */,
Expand Down Expand Up @@ -3106,12 +3120,15 @@
BEF5D2E6294A18B300FFD56D /* BTPayPalLineItem.swift in Sources */,
BE349113294B798300D2CF68 /* BTPayPalRequest.swift in Sources */,
BE549F112BF5445F00B6F441 /* BTPayPalReturnURL.swift in Sources */,
45E8CE502D2C773600D7A2DC /* PayPalExperienceProfilePOSTBody.swift in Sources */,
57544F5C295254A500DEB7B0 /* BTJSON+PayPal.swift in Sources */,
3B7A261129C0CAA40087059D /* BTPayPalAnalytics.swift in Sources */,
BE8E5CEF294B6937001BF017 /* BTPayPalCheckoutRequest.swift in Sources */,
807D22F02C29A93A009FFEA4 /* BTPayPalBillingCycle.swift in Sources */,
45E8CE4E2D28611700D7A2DC /* PayPalVaultPOSTBody.swift in Sources */,
5754481E294A2A1D00DEB7B0 /* BTPayPalCreditFinancingAmount.swift in Sources */,
57D9436E2968A8080079EAB1 /* BTPayPalLocaleCode.swift in Sources */,
45E8CE4C2D1F29BA00D7A2DC /* PayPalCheckoutPOSTBody.swift in Sources */,
57544F582952298900DEB7B0 /* BTPayPalAccountNonce.swift in Sources */,
8014221C2BAE935B009F9999 /* BTPayPalApprovalURLParser.swift in Sources */,
BE349111294B77E100D2CF68 /* BTPayPalVaultRequest.swift in Sources */,
Expand Down Expand Up @@ -3421,7 +3438,6 @@
buildActionMask = 2147483647;
files = (
427F32E025D1D62D00435294 /* BTPayPalClient_Tests.swift in Sources */,
42FC218B25CDE0290047C49A /* BTPayPalRequest_Tests.swift in Sources */,
42FC237125CE0E110047C49A /* BTPayPalCheckoutRequest_Tests.swift in Sources */,
BEDEAF112AC1D049004EA970 /* BTPayPalAccountNonce_Tests.swift in Sources */,
427F329025D1A7B900435294 /* BTPayPalVaultRequest_Tests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
amount: "5.00",
intent: newPayPalCheckoutToggle.isOn ? .sale : .authorize,
offerPayLater: payLaterToggle.isOn,
lineItems: [lineItem],
userAuthenticationEmail: emailTextField.text,
userPhoneNumber: BTPayPalPhoneNumber(
countryCode: countryCodeTextField.text ?? "",
nationalNumber: nationalNumberTextField.text ?? ""
),
lineItems: [lineItem]
)
)

payPalClient.tokenize(request) { nonce, error in
Expand Down
12 changes: 11 additions & 1 deletion Sources/BraintreeCore/BTPostalAddress.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Generic postal address
@objcMembers public class BTPostalAddress: NSObject {
@objcMembers public class BTPostalAddress: NSObject, Encodable {

// Property names follow the `Braintree_Address` convention as documented at:
// https://developer.paypal.com/braintree/docs/reference/request/address/create
Expand All @@ -27,4 +27,14 @@ import Foundation

/// Either a two-letter state code (for the US), or an ISO-3166-2 country subdivision code of up to three letters.
public var region: String?

enum CodingKeys: String, CodingKey {
case countryCodeAlpha2 = "country_code"
case extendedAddress = "line2"
case locality = "city"
case postalCode = "postal_code"
case region = "state"
case recipientName = "recipient_name"
case streetAddress = "line1"
}
}
10 changes: 10 additions & 0 deletions Sources/BraintreePayPal/BTConfiguration+PayPal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ extension BTConfiguration {
var isBillingAgreementsEnabled: Bool {
json?["paypal"]["billingAgreementsEnabled"].isTrue ?? false
}

/// Retrieves the display name associated with the PayPal account.
var displayName: String? {
json?["paypal"]["displayName"].asString()
}

/// Retrieves the currencyIsoCode.
var currencyIsoCode: String? {
json?["paypal"]["currencyIsoCode"].asString()
}
}
119 changes: 62 additions & 57 deletions Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,32 @@ import BraintreeCore
}

/// Options for the PayPal Checkout flow.
@objcMembers open class BTPayPalCheckoutRequest: BTPayPalRequest {

@objcMembers public class BTPayPalCheckoutRequest: NSObject, BTPayPalRequest {
// MARK: - Internal Properties

let hermesPath = "v1/paypal_hermes/create_payment_resource"
let paymentType: BTPayPalPaymentType = .checkout

var amount: String
var intent: BTPayPalRequestIntent
var userAction: BTPayPalRequestUserAction
var offerPayLater: Bool
var billingAgreementDescription: String?
var currencyCode: String?
var displayName: String?
var isShippingAddressEditable: Bool = false
var isShippingAddressRequired: Bool = false
var landingPageType: BTPayPalRequestLandingPageType?
var lineItems: [BTPayPalLineItem]?
var localeCode: BTPayPalLocaleCode?
var merchantAccountID: String?
var requestBillingAgreement: Bool

var riskCorrelationID: String?
var shippingAddressOverride: BTPostalAddress?
var userAuthenticationEmail: String?
var userPhoneNumber: BTPayPalPhoneNumber?

// MARK: - Initializer

/// Initializes a PayPal Native Checkout request
Expand All @@ -75,83 +90,73 @@ import BraintreeCore
/// - intent: Optional: Payment intent. Defaults to `.authorize`. Only applies to PayPal Checkout.
/// - userAction: Optional: Changes the call-to-action in the PayPal Checkout flow. Defaults to `.none`.
/// - offerPayLater: Optional: Offers PayPal Pay Later if the customer qualifies. Defaults to `false`. Only available with PayPal Checkout.
/// - billingAgreementDescription: Optional: Display a custom description to the user for a billing agreement. For Checkout with Vault flows, you must also set
/// - currencyCode: Optional: A three-character ISO-4217 ISO currency code to use for the transaction. Defaults to merchant currency code if not set.
/// See https://developer.paypal.com/docs/api/reference/currency-codes/ for a list of supported currency codes.
/// - displayName: Optional: The merchant name displayed inside of the PayPal flow; defaults to the company name on your Braintree account
/// - isShippingAddressEditable: Defaults to false. Set to true to enable user editing of the shipping address.
/// - isShippingAddressRequired: Defaults to false. When set to true, the shipping address selector will be displayed.
/// - landingPageType: Optional: Landing page type. Defaults to `.none`.
/// - Note: Setting the BTPayPalRequest's landingPageType changes the PayPal page to display when a user lands on the PayPal site to complete the payment.
/// `.login` specifies a PayPal account login page is used.
/// `.billing` specifies a non-PayPal account landing page is used.
/// - lineItems: Optional: The line items for this transaction. It can include up to 249 line items.
/// - localeCode: Optional: A locale code to use for the transaction.
/// - merchantAccountID: Optional: A non-default merchant account to use for tokenization.
/// - requestBillingAgreement: Optional: If set to `true`, this enables the Checkout with Vault flow, where the customer will be prompted to consent to a billing agreement
/// during checkout. Defaults to `false`.
/// - riskCorrelationID: Optional: A risk correlation ID created with Set Transaction Context on your server.
/// - shippingAddressOverride: Optional: A valid shipping address to be displayed in the transaction flow. An error will occur if this address is not valid.
/// - userAuthenticationEmail: Optional: User email to initiate a quicker authentication flow in cases where the user has a PayPal Account with the same email.
/// - userPhoneNumber: Optional: A user's phone number to initiate a quicker authentication flow in the scenario where the user has a PayPal account
/// identified with the same phone number.
/// - lineItems: Optional: The line items for this transaction. It can include up to 249 line items.
public init(
amount: String,
intent: BTPayPalRequestIntent = .authorize,
userAction: BTPayPalRequestUserAction = .none,
offerPayLater: Bool = false,
billingAgreementDescription: String? = nil,
currencyCode: String? = nil,
displayName: String? = nil,
isShippingAddressEditable: Bool = false,
isShippingAddressRequired: Bool = false,
landingPageType: BTPayPalRequestLandingPageType = .none,
lineItems: [BTPayPalLineItem]? = nil,
localeCode: BTPayPalLocaleCode = .none,
merchantAccountID: String? = nil,
requestBillingAgreement: Bool = false,
riskCorrelationID: String? = nil,
shippingAddressOverride: BTPostalAddress? = nil,
userAuthenticationEmail: String? = nil,
userPhoneNumber: BTPayPalPhoneNumber? = nil,
lineItems: [BTPayPalLineItem]? = nil
userPhoneNumber: BTPayPalPhoneNumber? = nil
) {
self.amount = amount
self.intent = intent
self.userAction = userAction
self.offerPayLater = offerPayLater
self.billingAgreementDescription = billingAgreementDescription
self.currencyCode = currencyCode
self.displayName = displayName
self.isShippingAddressEditable = isShippingAddressEditable
self.isShippingAddressRequired = isShippingAddressRequired
self.landingPageType = landingPageType
self.lineItems = lineItems
self.localeCode = localeCode
self.merchantAccountID = merchantAccountID
self.requestBillingAgreement = requestBillingAgreement
super.init(
hermesPath: "v1/paypal_hermes/create_payment_resource",
paymentType: .checkout,
lineItems: lineItems,
userAuthenticationEmail: userAuthenticationEmail,
userPhoneNumber: userPhoneNumber
)
self.riskCorrelationID = riskCorrelationID
self.shippingAddressOverride = shippingAddressOverride
self.userAuthenticationEmail = userAuthenticationEmail
self.userPhoneNumber = userPhoneNumber
}

// MARK: Internal Methods

override func parameters(
with configuration: BTConfiguration,
universalLink: URL? = nil,
isPayPalAppInstalled: Bool = false
) -> [String: Any] {
var baseParameters = super.parameters(with: configuration)
var checkoutParameters: [String: Any] = [
"intent": intent.stringValue,
"amount": amount,
"offer_pay_later": offerPayLater
]

let currencyCode = currencyCode != nil ? currencyCode : configuration.json?["paypal"]["currencyIsoCode"].asString()

if currencyCode != nil {
checkoutParameters["currency_iso_code"] = currencyCode
}

if userAction != .none, var experienceProfile = baseParameters["experience_profile"] as? [String: Any] {
experienceProfile["user_action"] = userAction.stringValue
baseParameters["experience_profile"] = experienceProfile
}

if requestBillingAgreement != false {
checkoutParameters["request_billing_agreement"] = requestBillingAgreement

if billingAgreementDescription != nil {
checkoutParameters["billing_agreement_details"] = ["description": billingAgreementDescription]
}
}

if shippingAddressOverride != nil {
checkoutParameters["line1"] = shippingAddressOverride?.streetAddress
checkoutParameters["line2"] = shippingAddressOverride?.extendedAddress
checkoutParameters["city"] = shippingAddressOverride?.locality
checkoutParameters["state"] = shippingAddressOverride?.region
checkoutParameters["postal_code"] = shippingAddressOverride?.postalCode
checkoutParameters["country_code"] = shippingAddressOverride?.countryCodeAlpha2
checkoutParameters["recipient_name"] = shippingAddressOverride?.recipientName
}

return baseParameters.merging(checkoutParameters) { $1 }

func encodedPostBodyWith(
configuration: BTConfiguration,
isPayPalAppInstalled: Bool = false,
universalLink: URL? = nil
) -> Encodable {
PayPalCheckoutPOSTBody(payPalRequest: self, configuration: configuration)
}
}
Loading