upi 1.0.2 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71e0504743eed34e876973cbef51a82d05d0f0c2281ec993e0ae40c7af4a161d
4
- data.tar.gz: b52d3e506c1f20e52ae4e18403871cae5768d1614d94ab452476e21e809a3593
3
+ metadata.gz: fbc938b77f542923739627acea2a7b852324d4e1facc7abc9e110fb57d6a468f
4
+ data.tar.gz: cb6e4d8010da2c1cec18469c08edef3a4349807033fd68d04a6d209042443a64
5
5
  SHA512:
6
- metadata.gz: 8c9aad17178913426a3479b69e6bdaa9e7a2fc7384786397b276f8d306716a542b7547c72b5a8ccaac9e6cddb8b402aae59d2eb91aadd4153ea885af201a8970
7
- data.tar.gz: 93fd0b0408baf19189852db59044f9119f0529ebd54895cc6deb1da27edad0167b03f7d003ff6d71c6b837ebd647ce9b6c20c8fb533e1079b454d4eaa4683b72
6
+ metadata.gz: 10bd3fdca2b006501ae4166c96443217ddd3bf72dc8c12d5474aeee346e5b56f48339bd413fca25c33aada355069b53021337930b33bd04b5de1e41007d9b5fa
7
+ data.tar.gz: 17475c5118a332063e18d4547e021dccce597922c589f7e9c819e494b869881e2eaea5ec82b54a364ccfd4b729069e07e02e1593f114ba712f1da2cfbf872394
data/.idea/upi.iml CHANGED
@@ -23,8 +23,8 @@
23
23
  <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-3.1.0) [gem]" level="application" />
24
24
  <orderEntry type="library" scope="PROVIDED" name="rake (v13.2.1, RVM: ruby-3.1.0) [gem]" level="application" />
25
25
  <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.9.2, RVM: ruby-3.1.0) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="rqrcode (v1.2.0, RVM: ruby-3.1.0) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="rqrcode_core (v0.2.0, RVM: ruby-3.1.0) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rqrcode (v2.2.0, RVM: ruby-3.1.0) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rqrcode_core (v1.2.0, RVM: ruby-3.1.0) [gem]" level="application" />
28
28
  <orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.0, RVM: ruby-3.1.0) [gem]" level="application" />
29
29
  <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.1, RVM: ruby-3.1.0) [gem]" level="application" />
30
30
  <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.2, RVM: ruby-3.1.0) [gem]" level="application" />
@@ -39,21 +39,21 @@
39
39
  <option name="myRootTask">
40
40
  <RakeTaskImpl id="rake">
41
41
  <subtasks>
42
- <RakeTaskImpl description="Build upi-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
42
+ <RakeTaskImpl description="Build upi-2.0.0.gem into the pkg directory" fullCommand="build" id="build" />
43
43
  <RakeTaskImpl id="build">
44
44
  <subtasks>
45
- <RakeTaskImpl description="Generate SHA512 checksum if upi-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
45
+ <RakeTaskImpl description="Generate SHA512 checksum if upi-2.0.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
46
46
  </subtasks>
47
47
  </RakeTaskImpl>
48
48
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
49
49
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
50
- <RakeTaskImpl description="Build and install upi-0.1.0.gem into system gems" fullCommand="install" id="install" />
50
+ <RakeTaskImpl description="Build and install upi-2.0.0.gem into system gems" fullCommand="install" id="install" />
51
51
  <RakeTaskImpl id="install">
52
52
  <subtasks>
53
- <RakeTaskImpl description="Build and install upi-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
53
+ <RakeTaskImpl description="Build and install upi-2.0.0.gem into system gems without network access" fullCommand="install:local" id="local" />
54
54
  </subtasks>
55
55
  </RakeTaskImpl>
56
- <RakeTaskImpl description="Create tag v0.1.0 and build and push upi-0.1.0.gem to TODO: Set to your gem server 'https://example.com'" fullCommand="release[remote]" id="release[remote]" />
56
+ <RakeTaskImpl description="Create tag v2.0.0 and build and push upi-2.0.0.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
57
57
  <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
58
58
  <RakeTaskImpl id="rubocop">
59
59
  <subtasks>
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 CHANGED
@@ -11,6 +11,6 @@ gem 'rspec', '~> 3.0'
11
11
 
12
12
  gem 'rubocop', '~> 1.21'
13
13
 
14
- gem 'rqrcode', '~> 1.1'
14
+ gem 'rqrcode', '2.2.0'
15
15
 
16
16
  gem 'chunky_png'
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upi (1.0.2)
4
+ upi (2.0.1)
5
5
  chunky_png
6
- rqrcode (~> 1.1)
6
+ rqrcode (= 2.2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -21,10 +21,10 @@ GEM
21
21
  rainbow (3.1.1)
22
22
  rake (13.2.1)
23
23
  regexp_parser (2.9.2)
24
- rqrcode (1.2.0)
24
+ rqrcode (2.2.0)
25
25
  chunky_png (~> 1.0)
26
- rqrcode_core (~> 0.2)
27
- rqrcode_core (0.2.0)
26
+ rqrcode_core (~> 1.0)
27
+ rqrcode_core (1.2.0)
28
28
  rspec (3.13.0)
29
29
  rspec-core (~> 3.13.0)
30
30
  rspec-expectations (~> 3.13.0)
@@ -61,7 +61,7 @@ PLATFORMS
61
61
  DEPENDENCIES
62
62
  chunky_png
63
63
  rake (~> 13.0)
64
- rqrcode (~> 1.1)
64
+ rqrcode (= 2.2.0)
65
65
  rspec (~> 3.0)
66
66
  rubocop (~> 1.21)
67
67
  upi!
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
- ```ruby
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
- Example
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
- upi_id: 'test@upi',
66
- name: 'Test Name',
67
- amount: 100,
68
- note: 'Test Description'
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.generate_url
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/[USERNAME]/upi/blob/master/CODE_OF_CONDUCT.md).
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Upi
4
- VERSION = '1.0.2'
4
+ VERSION = '2.0.1'
5
5
  end
data/lib/upi.rb CHANGED
@@ -15,14 +15,12 @@ module Upi
15
15
  #
16
16
  # generator = Upi::Generator.new(
17
17
  # upi_id: 'test@upi',
18
- # name: 'Test Name',
19
- # amount: 100,
20
- # note: 'Test Description'
18
+ # name: 'Test Name'
21
19
  # )
22
20
  #
23
- # svg_content = generator.generate_qr(mode: :svg)
24
- # png_content = generator.generate_qr(mode: :png)
25
- # payment_url = generator.generate_url
21
+ # svg_content = generator.generate_qr(100, 'Personal Payment', mode: :svg)
22
+ # png_content = generator.generate_qr(100, 'Personal Payment', mode: :png)
23
+ # payment_url = generator.upi_content(100, 'Personal Payment')
26
24
  #
27
25
  # Parameters:
28
26
  # - `upi_id`: The UPI ID of the recipient.
@@ -38,33 +36,33 @@ module Upi
38
36
  # @example
39
37
  # generator = Upi::Generator.new(
40
38
  # upi_id: 'test@upi',
41
- # name: 'Test Name',
42
- # amount: 100
39
+ # name: 'Test Name'
43
40
  # )
44
- # svg_content = generator.generate_qr(mode: :svg)
41
+ # svg_content = generator.generate_qr(100, 'Personal Payment', mode: :svg)
45
42
  # File.write('qr_code.svg', svg_content)
46
43
  #
47
- # @see https://www.upi.gov.in/ for more details on UPI protocol
44
+ # @see https://www.npci.org.in/what-we-do/upi/product-overview for more details on UPI protocol
48
45
  class Generator
49
46
  attr_reader :params
50
47
 
51
- def initialize(upi_id:, name:, amount: nil, currency: 'INR', note: '', merchant_code: nil, transaction_ref_id: nil, transaction_id: nil, url: nil)
48
+ def initialize(upi_id:, name:, currency: 'INR', merchant_code: '0000')
52
49
  @params = {
53
50
  pa: upi_id,
54
51
  pn: name,
55
- am: amount,
52
+ am: '',
56
53
  cu: currency,
57
- tn: note,
54
+ tn: '',
58
55
  mc: merchant_code,
59
- tr: transaction_ref_id,
60
- tid: transaction_id,
61
- url: url
56
+ tr: nil,
57
+ tid: nil,
58
+ url: nil
62
59
  }.compact
63
60
  end
64
61
 
65
- def generate_qr(mode: :svg)
66
- content = upi_content
62
+ def generate_qr(amount = '0', note = '', transaction_ref_id: nil, transaction_id: nil, url: nil, mode: :svg)
63
+ content = upi_content(amount, note, transaction_ref_id: transaction_ref_id, transaction_id: transaction_id, url: url)
67
64
  qrcode = RQRCode::QRCode.new(content)
65
+ generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
68
66
 
69
67
  case mode
70
68
  when :svg
@@ -92,11 +90,24 @@ module Upi
92
90
  end
93
91
  end
94
92
 
95
- def upi_content
93
+ def upi_content(amount = '0', note = '', transaction_ref_id: nil, transaction_id: nil, url: nil)
94
+ generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
95
+
96
96
  # Manually construct the UPI URI string without URI::UPI
97
- query_string = URI.encode_www_form(params)
97
+ query_string = URI.encode_www_form(params.reject { |_k, v| v.nil? })
98
98
  "upi://pay?#{query_string}"
99
99
  end
100
+
101
+ private
102
+
103
+ def generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
104
+ @params[:am] = amount
105
+ @params[:tn] = note
106
+ @params[:tr] = transaction_ref_id
107
+ @params[:tid] = transaction_id
108
+ @params[:url] = url
109
+ @params
110
+ end
100
111
  end
101
112
 
102
113
  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: 1.0.2
4
+ version: 2.0.1
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-05 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rqrcode
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: 2.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: 2.2.0
41
41
  description: This gem generates UPI QR codes for payments. It can be used in e-commerce
42
42
  applications to generate QR codes for payments. The QR codes can be scanned by UPI
43
43
  apps to make payments. The gem uses the rqrcode gem to generate the QR codes.
@@ -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