Skip to content

Commit

Permalink
Update order retrieval to include customer ID and add test for listin…
Browse files Browse the repository at this point in the history
…g payment methods

- Modified `retrieve(orderId:)` method in `OrderRoutes` to accept a `customerId` parameter for enhanced order retrieval.
- Updated implementation in `JuspayOrderRoutes` to utilize the new `customerId` parameter.
- Added a new test case for listing all payment methods to improve test coverage.
  • Loading branch information
vamsii777 committed Dec 19, 2024
1 parent a583834 commit 5ecd4e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 3 additions & 7 deletions Sources/JuspayKit/Orders/OrderRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol OrderRoutes: JuspayAPIRoute {
/// - Returns: An `Order` object representing the retrieved order.
///
/// - Throws: An error if the order retrieval fails or if there's a network issue.
func retrieve(orderId: String) async throws -> Order
func retrieve(orderId: String, customerId: String) async throws -> Order

/// Creates a new order in the Juspay system.
///
Expand Down Expand Up @@ -50,13 +50,9 @@ public struct JuspayOrderRoutes: OrderRoutes {
/// - Returns: An `Order` object representing the retrieved order.
///
/// - Throws: An error if the order retrieval fails or if there's a network issue.
public func retrieve(orderId: String) async throws -> Order {
public func retrieve(orderId: String, customerId: String) async throws -> Order {
var _headers = headers
let currentDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let formattedDate = dateFormatter.string(from: currentDate)
_headers.add(name: "version", value: formattedDate)
_headers.add(name: "x-routing-id", value: customerId)
return try await apiHandler.send(method: .GET, path: "orders/\(orderId)", headers: _headers)
}

Expand Down
8 changes: 7 additions & 1 deletion Tests/JuspayKitTests/JuspayKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ struct JuspayKitTests {
#expect(session != nil)
}

@Test("List all payment methods")
func listPaymentMethods() async throws {
let paymentMethods = try await juspayClient.paymentMethods.list()
#expect(paymentMethods != nil)
}

@Test("Retrieve an order")
func retrieveOrder() async throws {
let order = try await juspayClient.orders.retrieve(orderId: "OiVWluhiNXAQtR10BQaK")
let order = try await juspayClient.orders.retrieve(orderId: "OBug0anmAxDG2ncPhBsA", customerId: "4C2AD8F11484CE")
#expect(order != nil)
}

Expand Down

0 comments on commit 5ecd4e5

Please sign in to comment.