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 18 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
vankads marked this conversation as resolved.
Show resolved Hide resolved
lineItem.imageURL = URL(string: "https://www.example.com/example.jpg")
request.lineItems = [lineItem]

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

/// Use this option to specify the UPC type of the line item.
@objc public enum BTPayPalLineItemUPCType: Int {
case none
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

var stringValue: String? {
switch self {
case .none:
return nil
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"
}
}
}

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

Expand All @@ -31,12 +78,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 = .none

// MARK: - Public Initializer

Expand Down Expand Up @@ -82,6 +138,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 upcType.stringValue != nil {
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;
vankads marked this conversation as resolved.
Show resolved Hide resolved
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