upi 1.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a37c055bc91cf1e03c77c5f34e4faf6d4ab3c9a36040b35666f8852bfb2a393
4
- data.tar.gz: 04af7b5a7bbdd2e5de3f6373b81d07f2249f1fedd6c25dedc8f1da126c007abb
3
+ metadata.gz: f8cb1d258db77f6218b9b67f03028bd3d6331d92404cf76f4771af573b3aced4
4
+ data.tar.gz: 70db7b684507b4323cc783755de003ea6539cca0e96d5618a0b5877da16d280f
5
5
  SHA512:
6
- metadata.gz: 90a0302d1e18d5db151b47d05ea36ee7a4c5b393d2ecfba7fd9ed9dee02eeda464e2f6f021dbe25d9cf2a75e843d523caf3b5950f839917907f7927e408a559f
7
- data.tar.gz: fa8833dbdd9ea34ab2cad64af8657d4f088302926cf27119a0b5548111d5874d0f7845ecc3b5ebb8ee260f0426f336e75df8c89ce7e98e1094f16de67b0043bb
6
+ metadata.gz: 0430ba92e31a82fc6675d55359e7a07df82ae300c8b9d94bf0a487a900984e768a1f17cb86b40283c63c2fc9d90a11d984244216702b3f84845e1c695277d5e0
7
+ data.tar.gz: d0c18435b56755bef11c5ee1c177b1826a9f91b19992b04f6d824866d3aab4ac46e459bc349281f2940162daf2ea37b3188037ffdaecdd44df8d5a70395d137e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
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
+
11
+ ## [1.0.1] - 2024-09-05
12
+ - Linting Fixes
13
+
3
14
  ## [1.0.0] - 2024-09-05
4
15
 
5
16
  - Added `mode` option to `generate_qr` method to support both PNG and SVG formats.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upi (1.0.1)
4
+ upi (2.0.0)
5
5
  chunky_png
6
6
  rqrcode (~> 1.1)
7
7
 
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.1'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/upi.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rqrcode'
4
+ require 'chunky_png'
5
+ require 'uri'
4
6
  require_relative 'upi/version'
5
7
 
6
8
  module Upi
@@ -42,27 +44,28 @@ module Upi
42
44
  # svg_content = generator.generate_qr(mode: :svg)
43
45
  # File.write('qr_code.svg', svg_content)
44
46
  #
45
- # @see https://www.upi.gov.in/ for more details on UPI protocol
47
+ # @see https://www.npci.org.in/what-we-do/upi/product-overview for more details on UPI protocol
46
48
  class Generator
47
49
  attr_reader :params
48
50
 
49
- def initialize(upi_id:, name:, amount: nil, currency: 'INR', note: '', merchant_code: nil, transaction_ref_id: nil, transaction_id: nil, url: nil)
51
+ def initialize(upi_id:, name:, currency: 'INR', merchant_code: '0000')
50
52
  @params = {
51
53
  pa: upi_id,
52
54
  pn: name,
53
- am: amount,
55
+ am: '',
54
56
  cu: currency,
55
- tn: note,
57
+ tn: '',
56
58
  mc: merchant_code,
57
- tr: transaction_ref_id,
58
- tid: transaction_id,
59
- url: url
59
+ tr: nil,
60
+ tid: nil,
61
+ url: nil
60
62
  }.compact
61
63
  end
62
64
 
63
- def generate_qr(mode: :svg)
64
- 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)
65
67
  qrcode = RQRCode::QRCode.new(content)
68
+ generate_transaction(amount, note, transaction_id, transaction_ref_id, url)
66
69
 
67
70
  case mode
68
71
  when :svg
@@ -90,11 +93,24 @@ module Upi
90
93
  end
91
94
  end
92
95
 
93
- 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
+
94
99
  # Manually construct the UPI URI string without URI::UPI
95
- query_string = URI.encode_www_form(params)
100
+ query_string = URI.encode_www_form(params.reject { |_k, v| v.nil? })
96
101
  "upi://pay?#{query_string}"
97
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
98
114
  end
99
115
 
100
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: 1.0.1
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-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
@@ -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