PhonePeKit

PhonePeKit 是一个 Swift 包,用于与 PhonePe API 进行通信,以构建服务器端 Swift 应用程序。

PhonePeKit 的灵感很大程度上来自于 StripeKit,这是一个由 @andrewangeta 开发的项目。我们非常感谢 Stripe-Kit 中提出的框架和设计原则,它们指导了 PhonePeKit 在 Swift 生态系统中的开发。

安装

要开始使用 PhonePeKit,请在您的 Package.swift 文件中添加以下内容

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

使用 API

初始化 PhonePeClient

let httpClient = HTTPClient(..)

let saltKey = "14fa5465-f8a7-443f-8477-f986b8fcfde9"
let saltIndex = "1"
   
let phonePe = PhonePeClient(httpClient: httpClient, saltKey: saltKey, saltIndex: saltIndex, environment: .sandbox)

现在您可以通过 phonePe 访问 API。

您可用的 API 与已实现的功能相对应。

例如,要使用 Recurring Payments API,PhonePeClient 具有一个属性,可以通过路由访问该 API。

do {
    let request = CreateUserSubscriptionRequest(
        merchantId: "PGTESTPAYUAT77",
        merchantSubscriptionId: "MSUB123456789012345",
        merchantUserId: "MU123456789",
        authWorkflowType: .pennyDrop,  // or .pennyDrop
        amountType: .fixed,  // or .variable
        amount: 39900,  // Sample amount in paise
        frequency: .monthly,  // Choose the appropriate frequency
        recurringCount: 12,  // Sample recurring count
        subMerchantId: "DemoMerchant",
        mobileNumber: "7989378465",  // Sample mobile number
        deviceContext: DeviceContext(phonePeVersionCode: 400922)  // Sample device context
    )

    let subscriptions = try await phonePeClient.subscriptions.createSubscription(request: request)
    
    if subscriptions.status == .succeeded {
        print("New swift servers are on the way 🚀")
    } else {
        print("Sorry you have to use Node.js 🤢")
    }
} catch {
    // Handle error
}

已实现的功能

PG 标准结账 API

PG 自定义结账 API

其他

定期付款

许可证

PhonePeKit 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。