Razorpay for SwiftUI
dependencies: [
.package(url: "https://github.com/hritikutekar/RazorpaySwiftUI.git")
]
Use the razorpayCheckoutSheet View extension
Button("Checkout") {
showPaymentSheet.toggle()
}
.disabled(showPaymentSheet)
.razorpayCheckoutSheet(
isPresented: $showPaymentSheet,
amount: (Int(amount) ?? 0) * 100,
onSuccess: { paymentId in
description = "Payment success: \(paymentId)"
},
onError: { errorCode, description in
self.description = "Payment failed(\(errorCode)): \(description)"
}
)
import SwiftUI
import RazorpaySwiftUI
struct ContentView: View {
@State private var showPaymentSheet: Bool = false
@State private var amount: String = ""
@State private var description: String = ""
var body: some View {
Form {
TextField("Amount", text: $amount)
.keyboardType(.numberPad)
Button("Checkout") {
showPaymentSheet.toggle()
}
.disabled(showPaymentSheet)
.razorpayCheckoutSheet(
isPresented: $showPaymentSheet,
amount: (Int(amount) ?? 0) * 100,
onSuccess: { paymentId in
description = "Payment success: \(paymentId)"
},
onError: { errorCode, description in
self.description = "Payment failed(\(errorCode)): \(description)"
}
)
Text(description)
}
}
}