Skip to content

Commit

Permalink
Remove unnecessary parameters methods
Browse files Browse the repository at this point in the history
  • Loading branch information
richherrera committed Jan 13, 2025
1 parent f90356b commit df8eba1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 104 deletions.
43 changes: 0 additions & 43 deletions Sources/BraintreePayPal/BTPayPalLineItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,47 +146,4 @@ import Foundation
case upcType = "upc_type"
case url
}

// MARK: - Internal Methods

/// Returns the line item in a dictionary.
/// - Returns: A dictionary with the line item information formatted for a request.
func requestParameters() -> [String: String] {
var requestParameters = [
"quantity": quantity,
"unit_amount": unitAmount,
"name": name,
"kind": kind == .debit ? "debit" : "credit"
]

if let unitTaxAmount, !unitTaxAmount.isEmpty {
requestParameters["unit_tax_amount"] = unitAmount
}

if let itemDescription, !itemDescription.isEmpty {
requestParameters["description"] = itemDescription
}

if let productCode, !productCode.isEmpty {
requestParameters["product_code"] = productCode
}

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

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

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

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

return requestParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,4 @@ public struct BTPayPalRecurringBillingDetails: Encodable {
case taxAmount = "tax_amount"
case totalAmount = "total_amount"
}

// MARK: - Internal Methods

func parameters() -> [String: Any] {
var parameters: [String: Any] = [
"total_amount": totalAmount,
"currency_iso_code": currencyISOCode,
"billing_cycles": billingCycles.map { $0.parameters() }
]

if let productName {
parameters["name"] = productName
}

if let productDescription {
parameters["product_description"] = productDescription
}

if let productQuantity {
parameters["product_quantity"] = productQuantity
}

if let oneTimeFeeAmount {
parameters["one_time_fee_amount"] = oneTimeFeeAmount
}

if let shippingAmount {
parameters["shipping_amount"] = shippingAmount
}

if let productAmount {
parameters["product_price"] = productAmount
}

if let taxAmount {
parameters["tax_amount"] = taxAmount
}

return parameters
}
}
42 changes: 21 additions & 21 deletions UnitTests/BraintreePayPalTests/BTPayPalLineItem_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ import XCTest
class BTPayPalLineItem_Tests: XCTestCase {

func testUPCTypeStringReturnsCorrectValue() {
var lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "10", name: "item-name", kind: .debit)
let lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "10", name: "item-name", kind: .debit)

lineItem.upcType = .UPC_A
var requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-A")
lineItem.upcType = .UPC_A
var requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-A")

lineItem.upcType = .UPC_B
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-B")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-B")

lineItem.upcType = .UPC_C
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-C")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-C")

lineItem.upcType = .UPC_D
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-D")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-D")

lineItem.upcType = .UPC_E
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-E")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-E")

lineItem.upcType = .UPC_2
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"]!, "UPC-2")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-2")

lineItem.upcType = .UPC_5
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["upc_type"], "UPC-5")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["upc_type"] as? String, "UPC-5")
}

func testKindStringReturnsCorrectValue() {
var lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "10", name: "item-name", kind: .debit)
var requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["kind"], "debit")

var requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["kind"] as? String, "debit")
lineItem = BTPayPalLineItem(quantity: "1", unitAmount: "10", name: "item-name", kind: .credit)
requestParams = lineItem.requestParameters()
XCTAssertEqual(requestParams["kind"], "credit")
requestParams = try? lineItem.toDictionary()
XCTAssertEqual(requestParams?["kind"] as? String, "credit")
}
}

0 comments on commit df8eba1

Please sign in to comment.