Skip to content

vamsii777/razorpay-kit

Repository files navigation

RazorpayKit

RazorpayKit is a Swift library for integrating with Razorpay's payment gateway. It supports managing orders, payments, subscriptions, webhooks and more.

Installation

Swift Package Manager

You can add RazorpayKit to your project via Swift Package Manager (SPM) by adding the following dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/vamsii777/razorpay-kit.git", from: "0.0.9")
]

Using the API

Initialize the RazorpayClient with your Razorpay API key, secret, and environment. This client will be your gateway to interacting with the Razorpay API.

let httpClient = HTTPClient(...)
let razorpay = RazorpayClient(httpClient: httpClient, key: "rzp_test_12345", secret: "your_secret")

And now you have access to the APIs via razorpay.

The APIs you have available correspond to what's implemented.

For example to use the orders API, the razorpayClient has a property to access that API via routes.

Creating an Order

let orderData = [
    "amount": 50000, // Specify amount in the smallest currency unit.
    "currency": "INR",
    "receipt": "order_rcptid_11"
]

let order = try await razorpayClient.order.create(data: orderData)
print("Created Order: \(order)")

Fetching a Payment

let paymentId = "pay_29QQoUBi66xm2f"
let payment = try await razorpayClient.payment.fetch(paymentID: paymentId)
print("Fetched Payment: \(payment)")

Managing Subscriptions

let subscriptionId = "sub_00000000000001"
let subscription = try await razorpayClient.subscription.fetch(subscriptionID: subscriptionId)
print("Fetched Subscription: \(subscription)")

What's Implemented

Core Resources

  • Accounts
  • Addons
  • Cards
  • Customers
  • Fund Accounts
  • IIN (Issuer Identification Number)
  • Invoices
  • Items
  • Orders
  • Payments
  • Payment Links
  • Products
  • QR Codes
  • Refunds
  • Settlements
  • Stakeholders
  • Subscriptions
  • Tokens
  • Transfers
  • Virtual Accounts
  • Webhooks

Additional Features

  • Authentication: Securely authenticate using your Razorpay key and secret.
  • Headers Management: Customize request headers for special use cases such as idempotent requests.
  • Asynchronous API Calls: Support for Swift's modern async/await pattern for clean and simple asynchronous API calls.

LICENSE

RazorpayKit is available under the MIT license. See the LICENSE file for more info.