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

[Important] Adding imageUrl, upcType, upcCode to PayPalLineItem #1165

Merged
merged 24 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Braintree iOS SDK Release Notes

## unreleased
* BraintreePayPal
* Add imageUrl, upcCode, upcType to BTPayPalLineItem
vankads marked this conversation as resolved.
Show resolved Hide resolved

## 6.11.0 (2023-12-20)
* Update all SDK errors to be public and [Equatable](https://developer.apple.com/documentation/swift/equatable) (fixes #1152 and #1080)
* BraintreeThreeDSecure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class PayPalWebCheckoutViewController: PaymentButtonBaseViewController {
sender.setTitle("Processing...", for: .disabled)
sender.isEnabled = false

let request = BTPayPalCheckoutRequest(amount: "4.30")
let request = BTPayPalCheckoutRequest(amount: "5.00")
vankads marked this conversation as resolved.
Show resolved Hide resolved
let lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "5.00", name: "item one 1234567", kind: .debit)
lineItem.upcCode = "123456789"
lineItem.upcType = BTPayPalLineItemUpcType.UPC_A
lineItem.imageUrl = URL(string: "https://www.example.com/example.jpg")
vankads marked this conversation as resolved.
Show resolved Hide resolved
request.lineItems = [lineItem]

payPalClient.tokenize(request) { nonce, error in
sender.isEnabled = true
Expand Down
73 changes: 71 additions & 2 deletions Sources/BraintreePayPal/BTPayPalLineItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,54 @@ import Foundation
case credit
}


/// Use this option to specify the Upc type of the lien item.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Use this option to specify the Upc type of the lien item.
/// Use this option to specify the UPC type of the line item.

Additionally are there more descriptive UPC code definitions somewhere that we can link to? I'm not sure what all these cases mean and assume merchants may be confused as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://en.wikipedia.org/wiki/Universal_Product_Code is the best we found about these definitions. Not sure if we can link wiki page.
PayPal developer documentation doesn't have much details https://developer.paypal.com/api/limited-release/orders/v2/#definition-universal_product_code

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, these docs are fine then since they seem to match paypal's public docs. We can hopefully assume merchants that use these know what they mean. 🙈

@objc public enum BTPayPalLineItemUpcType: Int {
vankads marked this conversation as resolved.
Show resolved Hide resolved

/// Upc Type A
case UPC_A

/// Upc Type B
case UPC_B

/// Upc Type C
case UPC_C

/// Upc Type D
case UPC_D

/// Upc Type E
case UPC_E

/// Upc Type 2
case UPC_2

/// Upc Type 5
case UPC_5

/// String value representing the integration.
var stringValue: String {
switch self {
case .UPC_A:
return "UPC-A"
case .UPC_B:
return "UPC-B"
case .UPC_C:
return "UPC-C"
case .UPC_D:
return "UPC-D"
case .UPC_E:
return "UPC-E"
case .UPC_2:
return "UPC-2"
case .UPC_5:
return "UPC-5"
default:
return ""
}
}
}

/// A PayPal line item to be displayed in the PayPal checkout flow.
@objcMembers public class BTPayPalLineItem: NSObject {

Expand All @@ -31,12 +79,21 @@ import Foundation

/// Optional: Item description. Maximum 127 characters.
public let itemDescription: String? = nil

/// Optional: The URL to product information.
public let url: URL? = nil

/// Optional: Product or UPC code for the item. Maximum 127 characters.
public let productCode: String? = nil

/// Optional: The URL to product image information.
public var imageURL: URL? = nil

/// Optional: The URL to product information.
public let url: URL? = nil
/// Optional: UPC code for the item.
public var upcCode: String? = nil

/// Optional: UPC type for the item.
public var upcType: BTPayPalLineItemUpcType? = nil
vankads marked this conversation as resolved.
Show resolved Hide resolved

// MARK: - Public Initializer

Expand Down Expand Up @@ -82,6 +139,18 @@ import Foundation
requestParameters["url"] = url.absoluteString
}

if let imageURL, imageURL != URL(string: "") {
requestParameters["image_url"] = imageURL.absoluteString
}

if let upcCode, upcCode != "" {
requestParameters["upc_code"] = upcCode
}

if let upcType, upcType.stringValue != "" {
requestParameters["upc_type"] = upcType.stringValue
}

return requestParameters
}
}
18 changes: 12 additions & 6 deletions UnitTests/BraintreePayPalTests/BTPayPalRequest_Tests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import XCTest
@testable import BraintreeCore
vankads marked this conversation as resolved.
Show resolved Hide resolved
@testable import BraintreePayPal

class BTPayPalRequest_Tests: XCTestCase {
Expand Down Expand Up @@ -46,8 +45,12 @@ class BTPayPalRequest_Tests: XCTestCase {
request.riskCorrelationID = "123-correlation-id"
request.merchantAccountID = "merchant-account-id"
request.isShippingAddressEditable = true

request.lineItems = [BTPayPalLineItem(quantity: "1", unitAmount: "1", name: "item", kind: .credit)]
vankads marked this conversation as resolved.
Show resolved Hide resolved

let lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "10", name: "item-name", kind: BTPayPalLineItemKind.debit);
lineItem.imageUrl = URL(string: "http://example/image.jpg");
lineItem.upcCode = "upc-code";
lineItem.upcType = BTPayPalLineItemUpcType.UPC_A;
request.lineItems = [lineItem]

let parameters = request.parameters(with: configuration)
guard let experienceProfile = parameters["experience_profile"] as? [String : Any] else { XCTFail(); return }
Expand All @@ -60,9 +63,12 @@ class BTPayPalRequest_Tests: XCTestCase {
XCTAssertEqual(parameters["correlation_id"] as? String, "123-correlation-id")
XCTAssertEqual(experienceProfile["address_override"] as? Bool, false)
XCTAssertEqual(parameters["line_items"] as? [[String : String]], [["quantity" : "1",
"unit_amount": "1",
"name": "item",
"kind": "credit"]])
"unit_amount": "10",
"name": "item-name",
"kind": "debit",
"upc_code": "upc-code",
"upc_type": "UPC-A",
"image_url": "http://example/image.jpg"]])

XCTAssertEqual(parameters["return_url"] as? String, "sdk.ios.braintree://onetouch/v1/success")
XCTAssertEqual(parameters["cancel_url"] as? String, "sdk.ios.braintree://onetouch/v1/cancel")
Expand Down
Loading