Skip to content

Commit

Permalink
Merge pull request #199 from razorpay/v1.3.6
Browse files Browse the repository at this point in the history
v1.3.6; CEPF-1283
  • Loading branch information
vivekshindhe authored Jan 31, 2024
2 parents 66c62c3 + 39e6161 commit 18fa1f6
Show file tree
Hide file tree
Showing 36 changed files with 7,066 additions and 6,596 deletions.
2 changes: 1 addition & 1 deletion Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down
87 changes: 52 additions & 35 deletions Example/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import UIKit
import Razorpay
import SafariServices

class CheckoutViewController: UIViewController {
class CheckoutViewController: UIViewController,RazorpayPaymentCompletionProtocolWithData {

var razorpayObj : RazorpayCheckout? = nil
var merchantDetails : MerchantsDetails = MerchantsDetails.getDefaultData()

let razorpayKey = "rzp_live_ILgsfZCZoFIKMb" // Sign up for a Razorpay Account(https://dashboard.razorpay.com/#/access/signin) and generate the API Keys(https://razorpay.com/docs/payment-gateway/dashboard-guide/settings/#api-keys/) from the Razorpay Dashboard.
let razorpayKey = "rzp_test_1DP5mmOlF5G5ag" // Sign up for a Razorpay Account(https://dashboard.razorpay.com/#/access/signin) and generate the API Keys(https://razorpay.com/docs/payment-gateway/dashboard-guide/settings/#api-keys/) from the Razorpay Dashboard.

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -55,10 +55,19 @@ class CheckoutViewController: UIViewController {
controller.delegate = self
}

private func presentAlert(withTitle title: String?, message : String?) {
DispatchQueue.main.async {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "Okay", style: .default)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
}


private func openRazorpayCheckout() {
// 1. Initialize razorpay object with provided key. Also depending on your requirement you can assign delegate to self. It can be one of the protocol from RazorpayPaymentCompletionProtocolWithData, RazorpayPaymentCompletionProtocol.
razorpayObj = RazorpayCheckout.initWithKey(razorpayKey, andDelegate: self)
razorpayObj = RazorpayCheckout.initWithKey(razorpayKey, andDelegateWithData: self)
let options: [AnyHashable:Any] = [
"prefill": [
"contact": "1234567890",
Expand All @@ -78,6 +87,14 @@ class CheckoutViewController: UIViewController {
print("Unable to initialize")
}
}

func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?) {
self.presentAlert(withTitle: "Payment Successful", message: response?.description)
}

func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?) {
self.presentAlert(withTitle: "Payment Failed", message: str+"\n"+response!.description)
}
}

extension CheckoutViewController : CustomizeDataDelegate {
Expand All @@ -89,43 +106,43 @@ extension CheckoutViewController : CustomizeDataDelegate {
}

// RazorpayPaymentCompletionProtocol - This will execute two methods 1.Error and 2. Success case. On payment failure you will get a code and description. In payment success you will get the payment id.
extension CheckoutViewController : RazorpayPaymentCompletionProtocol {

func onPaymentError(_ code: Int32, description str: String) {
print("error: ", code, str)
self.presentAlert(withTitle: "Alert", message: str)
}

func onPaymentSuccess(_ payment_id: String) {
print("success: ", payment_id)
self.presentAlert(withTitle: "Success", message: "Payment Succeeded")
}
}
//extension CheckoutViewController : RazorpayPaymentCompletionProtocol {
//
// func onPaymentError(_ code: Int32, description str: String) {
// print("error: ", code, str)
// self.presentAlert(withTitle: "Alert", message: str)
// }
//
// func onPaymentSuccess(_ payment_id: String) {
// print("success: ", payment_id)
// self.presentAlert(withTitle: "Success", message: "Payment Succeeded")
// }
//}

// RazorpayPaymentCompletionProtocolWithData - This will returns you the data in both error and success case. On payment failure you will get a code and description. In payment success you will get the payment id.
extension CheckoutViewController: RazorpayPaymentCompletionProtocolWithData {

func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?) {
print("error: ", code)
self.presentAlert(withTitle: "Alert", message: str)
}

func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?) {
print("success: ", payment_id)
self.presentAlert(withTitle: "Success", message: "Payment Succeeded")
}
}
//extension CheckoutViewController: RazorpayPaymentCompletionProtocolWithData {
//
// func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?) {
// print("error: ", code)
// self.presentAlert(withTitle: "Alert", message: str)
// }
//
// func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?) {
// print("success: ", payment_id)
// self.presentAlert(withTitle: "Success", message: "Payment Succeeded")
// }
//}


extension CheckoutViewController {
func presentAlert(withTitle title: String?, message : String?) {
DispatchQueue.main.async {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "Okay", style: .default)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
}
// func presentAlert(withTitle title: String?, message : String?) {
// DispatchQueue.main.async {
// let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
// let OKAction = UIAlertAction(title: "Okay", style: .default)
// alertController.addAction(OKAction)
// self.present(alertController, animated: true, completion: nil)
// }
// }
}

extension CheckoutViewController : SFSafariViewControllerDelegate {
Expand Down
Binary file modified Pod/Razorpay.xcframework/ios-arm64/Razorpay.framework/Assets.car
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if 0
#elif defined(__arm64__) && __arm64__
// Generated by Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
// Generated by Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
#ifndef RAZORPAY_SWIFT_H
#define RAZORPAY_SWIFT_H
#pragma clang diagnostic push
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 18fa1f6

Please sign in to comment.