payment_sandbox_rails 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/rails_payment_sandbox/gateway.rb +56 -0
- data/lib/rails_payment_sandbox/version.rb +5 -0
- data/lib/rails_payment_sandbox.rb +17 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 748257faeedddb09d15312c7d189d8f89b6fe12aa7da910dfab21715254ef932
|
4
|
+
data.tar.gz: 4a437f006220ff1ab3a2a29aa6ac7a4dc024641342ecbb0fae5fe99c75d973e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8066ca8d9031d209f50f4b0df8c42b17f0895dbe296688904bedc2efd6538040db1ae51dfaeb3cd14c8b4499d7ae4093e5ee2c392ec35973df109d197485119
|
7
|
+
data.tar.gz: aa85510d96555a6405fe29ec7f8519338af9c55ab4b16f248eafef1a889f0e9f150d25f2bc2076bfbbb72311abf0b05d6186f0050133dca7e05c5cdd39a44f1f
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RailsPaymentSandbox
|
2
|
+
class Gateway
|
3
|
+
# Supported gateways
|
4
|
+
GATEWAYS = %i[
|
5
|
+
stripe razorpay paypal paytm gpay apple_pay phonepe amazon_pay cashfree
|
6
|
+
].freeze
|
7
|
+
|
8
|
+
STATUSES = %i[success failed pending].freeze
|
9
|
+
|
10
|
+
attr_reader :gateway, :amount, :currency, :status, :transaction_id, :order_id
|
11
|
+
|
12
|
+
def initialize(gateway:, amount:, currency: "INR", status: nil, order_id: nil)
|
13
|
+
raise ArgumentError, "Unsupported gateway" unless GATEWAYS.include?(gateway.to_sym)
|
14
|
+
|
15
|
+
@gateway = gateway.to_sym
|
16
|
+
@amount = amount
|
17
|
+
@currency = currency
|
18
|
+
@status = status || STATUSES.sample
|
19
|
+
@transaction_id = generate_transaction_id
|
20
|
+
@order_id = order_id || generate_order_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def process
|
24
|
+
{
|
25
|
+
gateway: gateway,
|
26
|
+
order_id: order_id,
|
27
|
+
transaction_id: transaction_id,
|
28
|
+
amount: amount,
|
29
|
+
currency: currency,
|
30
|
+
status: status,
|
31
|
+
message: message
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def generate_transaction_id
|
38
|
+
"#{gateway.to_s[0..2].upcase}-#{Time.now.to_i}-#{rand(1000..9999)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_order_id
|
42
|
+
"ORD-#{Time.now.to_i}-#{rand(10000..99999)}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def message
|
46
|
+
case status
|
47
|
+
when :success
|
48
|
+
"Payment completed successfully via #{gateway.to_s.capitalize}"
|
49
|
+
when :failed
|
50
|
+
"Payment failed on #{gateway.to_s.capitalize}"
|
51
|
+
when :pending
|
52
|
+
"Payment is pending on #{gateway.to_s.capitalize}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_payment_sandbox/version"
|
4
|
+
require "rails_payment_sandbox/gateway"
|
5
|
+
|
6
|
+
module RailsPaymentSandbox
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :config
|
11
|
+
|
12
|
+
def configure
|
13
|
+
self.config ||= {}
|
14
|
+
yield(config) if block_given?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: payment_sandbox_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mrmalvi
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rspec
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '3.12'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '3.12'
|
26
|
+
description: Rails Payment Sandbox helps developers test payment flows locally without
|
27
|
+
hitting real gateways. It simulates Stripe, Razorpay, PayPal, and provides fake
|
28
|
+
transactions with random statuses.
|
29
|
+
email:
|
30
|
+
- malviyak00@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/rails_payment_sandbox.rb
|
36
|
+
- lib/rails_payment_sandbox/gateway.rb
|
37
|
+
- lib/rails_payment_sandbox/version.rb
|
38
|
+
homepage: https://github.com/mrmalvi/rails_payment_sandbox
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/mrmalvi/rails_payment_sandbox
|
43
|
+
source_code_uri: https://github.com/mrmalvi/rails_payment_sandbox
|
44
|
+
changelog_uri: https://github.com/mrmalvi/rails_payment_sandbox/blob/main/CHANGELOG.md
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.0.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.6.9
|
60
|
+
specification_version: 4
|
61
|
+
summary: Simulate multiple payment gateways locally with fake data for testing
|
62
|
+
test_files: []
|