Introducing PhonePeKit

Introducing PhonePeKit

Vamsi Madduluri

What is PhonePeKit?

PhonePeKit is a Swift package that provides a set of tools and interfaces to interact with the PhonePe API. It’s specifically tailored for developers working on server-side Swift applications, offering a seamless way to incorporate PhonePe’s payment functionalities.

Key Features of PhonePeKit

PhonePeKit comes packed with features that make it an essential tool for Swift developers:

PG Standard Checkout API

  • PAY: Easily initiate payments
  • Check Status: Verify the status of transactions

Recurring Payments

  • Create User Subscription: Manage user subscriptions efficiently

Beta 2 Enhancements

  • Refund: Process refunds directly through the API
  • User Subscription Status: Check the status of user subscriptions
  • VPA Validate: Validate Virtual Payment Addresses in real-time
  • Health Status: Monitor the health status of various payment instruments

⚠️ Note: Some features in Beta 2, particularly Health Status, have known issues that are being addressed.

Installation

Installing PhonePeKit is straightforward. Add it to your Package.swift:

.package(url: "https://github.com/vamsii777/phonepe-kit.git", from: "main")

Usage

Using PhonePeKit is intuitive. Here’s a quick example of initiating a payment:

import PhonePeKit

func initiatePayment() async throws -> PayRequest {
    let httpClient = HTTPClient(..)
    let phonepe = PhonePeClient(
        httpClient: httpClient, 
        saltKey: "your_salt_key", 
        saltIndex: "your_salt_index", 
        environment: .sandbox
    )
    
    let request = PayRequest(
        merchantId: "PGTESTPAYUAT",
        merchantTransactionId: "MT7850590068188104",
        amount: 10000,
        merchantUserId: "MUID123",
        redirectUrl: "https://webhook.site/redirect-url",
        redirectMode: .POST,
        callbackUrl: "https://webhook.site/callback-url",
        paymentInstrument: PayRequest.PaymentInstrument(type: .PAY_PAGE),
        mobileNumber: "9999999999"
    )
    
    let response = try await phonepe.payments.initiatePayment(request: request)
    return response
}

Task {
    do {
        let response = try await initiatePayment()
        print("Payment initiated successfully. Response: \(response)")
    } catch {
        print("Error initiating payment: \(error)")
    }
}

Future Directions

As PhonePeKit evolves, we plan to:

  • 🚀 Expand its capabilities
  • 🐛 Address known issues in the Health Status feature
  • 🤝 Welcome community contributions
  • 📈 Improve performance and reliability

💡 Pro Tip: We encourage feedback and contributions from the Swift developer community to make PhonePeKit even better.

Conclusion

PhonePeKit represents a significant step forward in simplifying the integration of PhonePe’s payment gateway into Swift applications. Its structured approach, inspired by StripeKit, makes it an invaluable tool for developers looking to add robust payment functionalities to their server-side Swift applications.

Stay tuned for more updates and feel free to contribute to the PhonePeKit project on GitHub! 🚀


Happy coding! 💻