Skip to content

Commit

Permalink
Add authRequestStatus for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsii777 committed Jan 1, 2024
1 parent b7db0bc commit 92a5554
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Sources/PhonePeKit/Recurring Payments/AuthStatusResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AuthStatusResponse.swift
//
//
// Created by Vamsi Madduluri on 01/01/24.
//

import Foundation

public struct AuthRequestStatusResponse: Codable {
var merchantId: String
var authRequestId: String
var transactionDetails: TransactionDetails?
var subscriptionDetails: SubscriptionDetails

struct TransactionDetails: Codable {
var providerReferenceId: String?
var amount: Int?
var state: String?
var payResponseCode: String?
var payResponseCodeDescription: String?
var paymentModes: [PaymentMode]?
}

struct SubscriptionDetails: Codable {
var subscriptionId: String
var state: String
}

struct PaymentMode: Codable {
var mode: String
var amount: Int
var utr: String?
var ifsc: String?
var maskedAccountNumber: String?
var umn: String?
}
}
16 changes: 16 additions & 0 deletions Sources/PhonePeKit/Recurring Payments/SubscriptionRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol SubscriptionRoutes: PhonePeAPIRoute {
func userSubscriptionStatus(merchantId: String, merchantSubscriptionId: String) async throws -> PhonePeResponse<UserSubscriptionStatusResponse>
func fetchAllSubscriptions(merchantId: String, merchantUserId: String) async throws -> PhonePeResponse<AllSubscriptionsResponse>
func verifyVPA(merchantId: String, vpa: String) async throws -> PhonePeResponse<VPAValidateResponse>
func authRequestStatus(merchantId: String, authRequestId: String) async throws -> PhonePeResponse<AuthRequestStatusResponse>
}

public struct PhonePeSubscriptionRoutes: SubscriptionRoutes {
Expand Down Expand Up @@ -84,6 +85,21 @@ public struct PhonePeSubscriptionRoutes: SubscriptionRoutes {
headers: requestHeaders
)
}

public func authRequestStatus(merchantId: String, authRequestId: String) async throws -> PhonePeResponse<AuthRequestStatusResponse> {
let path = "/v3/recurring/auth/status/\(merchantId)/\(authRequestId)"

var requestHeaders = headers
requestHeaders.add(name: "X-MERCHANT-ID", value: merchantId)
requestHeaders.add(name: "merchantId", value: merchantId)
requestHeaders.add(name: "authRequestId", value: authRequestId)

return try await apiHandler.send(
method: .GET,
path: path,
headers: requestHeaders
)
}
}


Expand Down
8 changes: 8 additions & 0 deletions Tests/PhonePeKitTests/PhonePeKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ class PhonePeClientTests: XCTestCase {
XCTAssertEqual(response.code, "SUCCESS")
}

// Fix Tests
func testAuthRequestStatus() async throws {
let phonePeClient = createClient(saltKey: "099eb0cd-02cf-4e2a-8aca-3e6c6aff0399", environment: .sandbox)
let response = try await phonePeClient.subscriptions.authRequestStatus(merchantId: "MID12345", authRequestId: "TX123456789")
XCTAssertNotNil(response)
XCTAssertEqual(response.code, "SUCCESS")
}

// USE PRODUCTION KEY & SALT
// Phonepe does not have an uptime test URL.
func healthStatus() async throws {
Expand Down

0 comments on commit 92a5554

Please sign in to comment.