Skip to content

CEPF-1193: Initial Commit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>RazorpayCheckout.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>checkout-swift-Package.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>checkout-swift</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016 Razorpay Software Pvt. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
32 changes: 32 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let packageVersion = "1.3.4"

let package = Package(
name: "RazorpayCheckout",
platforms: [
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "RazorpayCheckout",
targets: ["RazorpayCheckout", "Razorpay"]
),
],
targets: [
.target(
name: "RazorpayCheckout",
path: "RazorpayCheckout/Sources/RazorpayCheckoutCore"
),
.binaryTarget(
name: "Razorpay",
url: "https://github.com/razorpay/razorpay-pod/releases/download/\(packageVersion)/Razorpay.xcframework.zip",
checksum: "7a9aee4f56d1ff0bbedc19451b0c01f26640cb9b4b043502b6e8b3d1e1e3bbbe"
),
],
swiftLanguageVersions: [.v5]
)
8 changes: 8 additions & 0 deletions RazorpayCheckout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Razorpay

enum CheckoutErrors: Error {
case keyMissing
}

extension CheckoutErrors: CustomStringConvertible {

var description: String {
switch self {
case .keyMissing: return "Merchant Key is mandatory"
}
}
}

public protocol RazorpaySwiftProtocol {

}

public protocol PaymentCompletionDelegate: RazorpaySwiftProtocol {
func onPaymentError(_ code: Int32, description str: String)
func onPaymentSuccess(_ payment_id : String)
}

public protocol PaymentCompletionWithDataDelegate: RazorpaySwiftProtocol {
func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?)
func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?)
}

public final class RazorpaySwift {

private var razorpay: RazorpayCheckout?
private var key: String?
private var delegate: RazorpaySwiftProtocol?
private static let shared: RazorpaySwift = RazorpaySwift()

private init() {}

public static func initWithKey(key: String, andDelegate delegate: PaymentCompletionDelegate) -> RazorpaySwift {
RazorpaySwift.shared.key = key
RazorpaySwift.shared.delegate = delegate
return RazorpaySwift.shared
}

public static func initWithKey(key: String, andDelegateWithData delegate: PaymentCompletionWithDataDelegate) -> RazorpaySwift {
RazorpaySwift.shared.key = key
RazorpaySwift.shared.delegate = delegate
return RazorpaySwift.shared
}

public func open(withPayload payload: [AnyHashable: Any]) throws {
guard let key = self.key else {
throw CheckoutErrors.keyMissing
}
if self.razorpay == nil {
self.razorpay = RazorpayCheckout.initWithKey(key, andDelegate: self)
}

self.razorpay?.open(payload)
}
}

extension RazorpaySwift: RazorpayPaymentCompletionProtocol {
public func onPaymentError(_ code: Int32, description str: String) {
(self.delegate as? PaymentCompletionDelegate)?.onPaymentError(code, description: str)
}

public func onPaymentSuccess(_ payment_id: String) {
(self.delegate as? PaymentCompletionDelegate)?.onPaymentSuccess(payment_id)
}
}

extension RazorpaySwift: RazorpayPaymentCompletionProtocolWithData {
public func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?) {
(self.delegate as? PaymentCompletionWithDataDelegate)?.onPaymentError(code, description: str, andData: response)
}

public func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?) {
(self.delegate as? PaymentCompletionWithDataDelegate)?.onPaymentSuccess(payment_id, andData: response)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
@testable import RazorpayCheckout

final class RazorpayCheckoutTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}