upi 1.0.2 → 2.0.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +52 -19
- data/lib/upi/version.rb +1 -1
- data/lib/upi.rb +25 -11
- data/sig/upi/generator.rbs +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cb1d258db77f6218b9b67f03028bd3d6331d92404cf76f4771af573b3aced4
|
4
|
+
data.tar.gz: 70db7b684507b4323cc783755de003ea6539cca0e96d5618a0b5877da16d280f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0430ba92e31a82fc6675d55359e7a07df82ae300c8b9d94bf0a487a900984e768a1f17cb86b40283c63c2fc9d90a11d984244216702b3f84845e1c695277d5e0
|
7
|
+
data.tar.gz: d0c18435b56755bef11c5ee1c177b1826a9f91b19992b04f6d824866d3aab4ac46e459bc349281f2940162daf2ea37b3188037ffdaecdd44df8d5a70395d137e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [2.0.0] - 2024-09-06
|
4
|
+
- Add support for changing amounts after initialization
|
5
|
+
- Make Merchant Code default 0000 for individual users
|
6
|
+
|
7
|
+
## [1.0.2] - 2024-09-05
|
8
|
+
- Fixed `generate_qr` method to return the QR code as a string instead of writing it to a file.
|
9
|
+
- Updated README with new usage instructions.
|
10
|
+
|
3
11
|
## [1.0.1] - 2024-09-05
|
4
12
|
- Linting Fixes
|
5
13
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,56 +20,89 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Usage
|
24
23
|
Generating a QR Code
|
25
24
|
To generate a UPI QR code, you need to initialize the Upi::Generator class with the required parameters and call the generate_qr method.
|
26
25
|
|
27
|
-
Example
|
26
|
+
### Example
|
28
27
|
|
29
|
-
|
30
|
-
require 'upi'
|
31
|
-
```
|
28
|
+
Individual Mode:
|
32
29
|
|
33
30
|
### Create a new UPI QR code generator instance
|
34
31
|
```ruby
|
32
|
+
require 'upi'
|
33
|
+
|
35
34
|
generator = Upi::Generator.new(
|
36
35
|
upi_id: 'test@upi',
|
37
|
-
name: 'Test Name'
|
38
|
-
amount: 100,
|
39
|
-
note: 'Test Description'
|
36
|
+
name: 'Test Name'
|
40
37
|
)
|
41
38
|
|
39
|
+
# NOTE: For Individual Mode the Merchant Code is always 0000 which the code handles by default
|
40
|
+
|
42
41
|
```
|
43
42
|
|
44
43
|
### Generate QR code in SVG format
|
45
44
|
```ruby
|
46
|
-
svg_content = generator.generate_qr(mode: :svg)
|
45
|
+
svg_content = generator.generate_qr(100, 'Personal Payment', mode: :svg)
|
47
46
|
File.write('qr_code.svg', svg_content)
|
48
47
|
```
|
49
48
|
|
50
49
|
### Generate QR code in PNG format
|
51
50
|
```ruby
|
52
|
-
png_content = generator.generate_qr(mode: :png)
|
51
|
+
png_content = generator.generate_qr(100, 'Personal Payment', mode: :png)
|
53
52
|
File.binwrite('qr_code.png', png_content)
|
54
53
|
```
|
55
54
|
|
56
55
|
### Generating a Payment URL
|
57
56
|
You can generate a UPI payment URL suitable for use in HTML links by using the generate_url method. This URL can be used as the href attribute in a "Pay Now" button or link.
|
58
57
|
|
59
|
-
|
58
|
+
```ruby
|
59
|
+
# Generate UPI payment URL
|
60
|
+
payment_url = generator.upi_content(100, 'Personal Payment')
|
61
|
+
puts payment_url
|
62
|
+
|
63
|
+
# The generate_url method returns a UPI URI string that can be used as a link in your HTML:
|
64
|
+
```
|
65
|
+
|
66
|
+
```html
|
67
|
+
<a href="<%= payment_url %>">Pay Now</a>
|
68
|
+
```
|
69
|
+
|
70
|
+
Merchant Mode:
|
71
|
+
|
72
|
+
### Create a new UPI QR code generator instance
|
60
73
|
```ruby
|
61
74
|
require 'upi'
|
62
75
|
|
63
|
-
# Create a new UPI URL generator instance
|
64
76
|
generator = Upi::Generator.new(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
upi_id: 'test@upi',
|
78
|
+
name: 'Test Name',
|
79
|
+
merchant_code: '1234',
|
80
|
+
currency: 'INR'
|
81
|
+
)
|
82
|
+
|
83
|
+
# NOTE: For Merchant Mode the Merchant Code needs to be set explicitly
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
### Generate QR code in SVG format
|
88
|
+
```ruby
|
89
|
+
svg_content = generator.generate_qr(500, 'Payment for Goods', transaction_ref_id: 'REF123', transaction_id: 'TXN456', url: 'https://merchant.com/payment', mode: :svg)
|
90
|
+
File.write('qr_code_merchant.svg', svg_content)
|
91
|
+
```
|
70
92
|
|
93
|
+
### Generate QR code in PNG format
|
94
|
+
```ruby
|
95
|
+
png_content = generator.generate_qr(500, 'Payment for Goods', transaction_ref_id: 'REF123', transaction_id: 'TXN456', url: 'https://merchant.com/payment', mode: :png)
|
96
|
+
File.binwrite('qr_code_merchant.png', png_content)
|
97
|
+
```
|
98
|
+
|
99
|
+
### Generating a Payment URL
|
100
|
+
You can generate a UPI payment URL suitable for use in HTML links by using the generate_url method. This URL can be used as the href attribute in a "Pay Now" button or link.
|
101
|
+
|
102
|
+
|
103
|
+
```ruby
|
71
104
|
# Generate UPI payment URL
|
72
|
-
payment_url = generator.
|
105
|
+
payment_url = generator.upi_content(500, 'Payment for Goods', transaction_ref_id: 'REF123', transaction_id: 'TXN456', url: 'https://merchant.com/payment')
|
73
106
|
puts payment_url
|
74
107
|
|
75
108
|
# The generate_url method returns a UPI URI string that can be used as a link in your HTML:
|
@@ -118,4 +151,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
118
151
|
|
119
152
|
## Code of Conduct
|
120
153
|
|
121
|
-
Everyone interacting in the Upi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
154
|
+
Everyone interacting in the Upi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/stingrayzboy/upi/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/upi/version.rb
CHANGED
data/lib/upi.rb
CHANGED
@@ -44,27 +44,28 @@ module Upi
|
|
44
44
|
# svg_content = generator.generate_qr(mode: :svg)
|
45
45
|
# File.write('qr_code.svg', svg_content)
|
46
46
|
#
|
47
|
-
# @see https://www.
|
47
|
+
# @see https://www.npci.org.in/what-we-do/upi/product-overview for more details on UPI protocol
|
48
48
|
class Generator
|
49
49
|
attr_reader :params
|
50
50
|
|
51
|
-
def initialize(upi_id:, name:,
|
51
|
+
def initialize(upi_id:, name:, currency: 'INR', merchant_code: '0000')
|
52
52
|
@params = {
|
53
53
|
pa: upi_id,
|
54
54
|
pn: name,
|
55
|
-
am:
|
55
|
+
am: '',
|
56
56
|
cu: currency,
|
57
|
-
tn:
|
57
|
+
tn: '',
|
58
58
|
mc: merchant_code,
|
59
|
-
tr:
|
60
|
-
tid:
|
61
|
-
url:
|
59
|
+
tr: nil,
|
60
|
+
tid: nil,
|
61
|
+
url: nil
|
62
62
|
}.compact
|
63
63
|
end
|
64
64
|
|
65
|
-
def generate_qr(mode: :svg)
|
66
|
-
content = upi_content
|
65
|
+
def generate_qr(amount = '0', note = '', transaction_ref_id: nil, transaction_id: nil, url: nil, mode: :svg)
|
66
|
+
content = upi_content(amount, note, transaction_ref_id: transaction_ref_id, transaction_id: transaction_id, url: url)
|
67
67
|
qrcode = RQRCode::QRCode.new(content)
|
68
|
+
generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
|
68
69
|
|
69
70
|
case mode
|
70
71
|
when :svg
|
@@ -92,11 +93,24 @@ module Upi
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
|
-
def upi_content
|
96
|
+
def upi_content(amount = '0', note = '', transaction_ref_id: nil, transaction_id: nil, url: nil)
|
97
|
+
generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
|
98
|
+
|
96
99
|
# Manually construct the UPI URI string without URI::UPI
|
97
|
-
query_string = URI.encode_www_form(params)
|
100
|
+
query_string = URI.encode_www_form(params.reject { |_k, v| v.nil? })
|
98
101
|
"upi://pay?#{query_string}"
|
99
102
|
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
|
107
|
+
@params[:am] = amount
|
108
|
+
@params[:tn] = note
|
109
|
+
@params[:tr] = transaction_ref_id
|
110
|
+
@params[:tid] = transaction_id
|
111
|
+
@params[:url] = url
|
112
|
+
@params
|
113
|
+
end
|
100
114
|
end
|
101
115
|
|
102
116
|
class Error < StandardError; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Upi
|
2
|
+
class Generator
|
3
|
+
@params: Hash[Symbol, String]
|
4
|
+
|
5
|
+
attr_reader params: Hash[Symbol, String]
|
6
|
+
|
7
|
+
def generate_qr: -> String
|
8
|
+
|
9
|
+
def upi_content: -> String
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def generate_transaction: -> Hash[Symbol, String]
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faraz Noor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/upi.rb
|
67
67
|
- lib/upi/version.rb
|
68
68
|
- sig/upi.rbs
|
69
|
+
- sig/upi/generator.rbs
|
69
70
|
homepage: https://github.com/stingrayzboy/upi
|
70
71
|
licenses:
|
71
72
|
- MIT
|