upi 0.1.0 → 1.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: 370ad6126107cc8bae31e35d695751725f443f03a92ccf3f7d4fa14097daad42
4
- data.tar.gz: f8ebadf5eb445cc67ead2099859df36db8d2e3d0915d4541ff4986952a18725a
3
+ metadata.gz: 9a37c055bc91cf1e03c77c5f34e4faf6d4ab3c9a36040b35666f8852bfb2a393
4
+ data.tar.gz: 04af7b5a7bbdd2e5de3f6373b81d07f2249f1fedd6c25dedc8f1da126c007abb
5
5
  SHA512:
6
- metadata.gz: 492867970d86c1a625263b74679701d527b3f2466270fb711b3227e49451341466d90af13d30f6447413029210ca7734ed265e19ba338732d36e8b7f22ee085d
7
- data.tar.gz: fffc1302656eeb5d85f4ec09c61e3805e2b640ddb1d5136478a0a2201b9b3f5e9021034137032535faca084d02a29818974c8f21ac73587f443bd46364b88587
6
+ metadata.gz: 90a0302d1e18d5db151b47d05ea36ee7a4c5b393d2ecfba7fd9ed9dee02eeda464e2f6f021dbe25d9cf2a75e843d523caf3b5950f839917907f7927e408a559f
7
+ data.tar.gz: fa8833dbdd9ea34ab2cad64af8657d4f088302926cf27119a0b5548111d5874d0f7845ecc3b5ebb8ee260f0426f336e75df8c89ce7e98e1094f16de67b0043bb
data/.rubocop.yml CHANGED
@@ -3,11 +3,20 @@ AllCops:
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
6
- EnforcedStyle: double_quotes
6
+ EnforcedStyle: single_quotes
7
7
 
8
8
  Style/StringLiteralsInInterpolation:
9
9
  Enabled: true
10
10
  EnforcedStyle: double_quotes
11
11
 
12
12
  Layout/LineLength:
13
- Max: 120
13
+ Max: 300
14
+
15
+ Metrics/MethodLength:
16
+ Max: 60
17
+
18
+ Metrics/BlockLength:
19
+ Max: 150
20
+
21
+ Metrics/ParameterLists:
22
+ Max: 15
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0] - 2024-09-05
4
+
5
+ - Added `mode` option to `generate_qr` method to support both PNG and SVG formats.
6
+ - Made `upi_content` method public for easier access.
7
+ - Improved handling of QR code generation and added detailed error handling.
8
+
3
9
  ## [0.1.0] - 2024-09-05
4
10
 
5
11
  - Initial release
data/Gemfile CHANGED
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in upi.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'rake', '~> 13.0'
9
9
 
10
- gem "rspec", "~> 3.0"
10
+ gem 'rspec', '~> 3.0'
11
11
 
12
- gem "rubocop", "~> 1.21"
12
+ gem 'rubocop', '~> 1.21'
13
13
 
14
- gem "rqrcode", "~> 1.1"
14
+ gem 'rqrcode', '~> 1.1'
15
+
16
+ gem 'chunky_png'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upi (0.1.0)
4
+ upi (1.0.1)
5
+ chunky_png
5
6
  rqrcode (~> 1.1)
6
7
 
7
8
  GEM
@@ -54,8 +55,11 @@ GEM
54
55
 
55
56
  PLATFORMS
56
57
  arm64-darwin-23
58
+ x86_64-darwin-23
59
+ x86_64-linux
57
60
 
58
61
  DEPENDENCIES
62
+ chunky_png
59
63
  rake (~> 13.0)
60
64
  rqrcode (~> 1.1)
61
65
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Upi
1
+ # UPI
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/upi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ The `upi` gem allows you to generate UPI QR codes for user-to-user payments. It supports both PNG and SVG formats for QR codes.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,87 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Usage
24
+ Generating a QR Code
25
+ 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
+
27
+ Example
28
+
29
+ ```ruby
30
+ require 'upi'
31
+ ```
32
+
33
+ ### Create a new UPI QR code generator instance
34
+ ```ruby
35
+ generator = Upi::Generator.new(
36
+ upi_id: 'test@upi',
37
+ name: 'Test Name',
38
+ amount: 100,
39
+ note: 'Test Description'
40
+ )
41
+
42
+ ```
43
+
44
+ ### Generate QR code in SVG format
45
+ ```ruby
46
+ svg_content = generator.generate_qr(mode: :svg)
47
+ File.write('qr_code.svg', svg_content)
48
+ ```
49
+
50
+ ### Generate QR code in PNG format
51
+ ```ruby
52
+ png_content = generator.generate_qr(mode: :png)
53
+ File.binwrite('qr_code.png', png_content)
54
+ ```
55
+
56
+ ### Generating a Payment URL
57
+ 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
+
59
+ Example
60
+ ```ruby
61
+ require 'upi'
62
+
63
+ # Create a new UPI URL generator instance
64
+ generator = Upi::Generator.new(
65
+ upi_id: 'test@upi',
66
+ name: 'Test Name',
67
+ amount: 100,
68
+ note: 'Test Description'
69
+ )
70
+
71
+ # Generate UPI payment URL
72
+ payment_url = generator.generate_url
73
+ puts payment_url
74
+
75
+ # The generate_url method returns a UPI URI string that can be used as a link in your HTML:
76
+ ```
77
+
78
+ ```html
79
+ <a href="<%= payment_url %>">Pay Now</a>
80
+ ```
81
+
82
+ #### In the example above:
83
+
84
+ * Replace `'test@upi'` with the UPI ID of the recipient.
85
+ * Replace `'Test Name'` with the recipient's name.
86
+ * The `amount` parameter specifies the payment amount.
87
+ * `note` is an optional field to include additional information.
88
+ Parameters
89
+ * upi_id: The UPI ID of the recipient.
90
+ * name: The name of the recipient.
91
+ * amount: The amount for the payment (required for UPI transactions).
92
+ * currency: Currency code (default is 'INR').
93
+ * note: Additional note or description for the payment.
94
+ * merchant_code: Optional merchant code.
95
+ * transaction_ref_id: Optional transaction reference ID.
96
+ * transaction_id: Optional transaction ID.
97
+ * url: Optional URL for additional information or payment redirect.
98
+
99
+ #### Handling PNG and SVG
100
+ You can specify the format of the QR code by using the mode parameter:
101
+
102
+ * mode: :svg generates an SVG format QR code.
103
+ * mode: :png generates a PNG format QR code.
26
104
 
27
105
  ## Development
28
106
 
@@ -32,7 +110,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
110
 
33
111
  ## Contributing
34
112
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/upi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/upi/blob/master/CODE_OF_CONDUCT.md).
113
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stingrayzboy/upi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/upi/blob/master/CODE_OF_CONDUCT.md).
36
114
 
37
115
  ## License
38
116
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "upi"
4
+ require 'bundler/setup'
5
+ require 'upi'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require "upi"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
data/lib/upi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Upi
4
- VERSION = "0.1.0"
4
+ VERSION = '1.0.1'
5
5
  end
data/lib/upi.rb CHANGED
@@ -1,9 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rqrcode'
4
- require_relative "upi/version"
4
+ require_relative 'upi/version'
5
5
 
6
6
  module Upi
7
+ # The Generator class is responsible for creating UPI QR codes and payment URLs.
8
+ #
9
+ # You can generate a QR code for a UPI payment in either SVG or PNG format,
10
+ # and also create a UPI payment URL for use in HTML links.
11
+ #
12
+ # Example usage:
13
+ #
14
+ # generator = Upi::Generator.new(
15
+ # upi_id: 'test@upi',
16
+ # name: 'Test Name',
17
+ # amount: 100,
18
+ # note: 'Test Description'
19
+ # )
20
+ #
21
+ # svg_content = generator.generate_qr(mode: :svg)
22
+ # png_content = generator.generate_qr(mode: :png)
23
+ # payment_url = generator.generate_url
24
+ #
25
+ # Parameters:
26
+ # - `upi_id`: The UPI ID of the recipient.
27
+ # - `name`: The name of the recipient.
28
+ # - `amount`: The payment amount (required for UPI transactions).
29
+ # - `currency`: The currency code (default is 'INR').
30
+ # - `note`: An optional note or description for the payment.
31
+ # - `merchant_code`: An optional merchant code.
32
+ # - `transaction_ref_id`: An optional transaction reference ID.
33
+ # - `transaction_id`: An optional transaction ID.
34
+ # - `url`: An optional URL for additional information or payment redirect.
35
+ #
36
+ # @example
37
+ # generator = Upi::Generator.new(
38
+ # upi_id: 'test@upi',
39
+ # name: 'Test Name',
40
+ # amount: 100
41
+ # )
42
+ # svg_content = generator.generate_qr(mode: :svg)
43
+ # File.write('qr_code.svg', svg_content)
44
+ #
45
+ # @see https://www.upi.gov.in/ for more details on UPI protocol
7
46
  class Generator
8
47
  attr_reader :params
9
48
 
@@ -21,20 +60,36 @@ module Upi
21
60
  }.compact
22
61
  end
23
62
 
24
- def generate_qr
63
+ def generate_qr(mode: :svg)
25
64
  content = upi_content
26
65
  qrcode = RQRCode::QRCode.new(content)
27
66
 
28
- # Output SVG format QR code
29
- qrcode.as_svg(
30
- color: '000',
31
- shape_rendering: 'crispEdges',
32
- module_size: 11
33
- )
67
+ case mode
68
+ when :svg
69
+ qrcode.as_svg(
70
+ color: '000',
71
+ shape_rendering: 'crispEdges',
72
+ module_size: 11
73
+ )
74
+ when :png
75
+ png = qrcode.as_png(
76
+ bit_depth: 1,
77
+ border_modules: 4,
78
+ color_mode: ChunkyPNG::COLOR_GRAYSCALE,
79
+ color: 'black',
80
+ file: nil,
81
+ fill: 'white',
82
+ module_px_size: 6, # Adjust size as needed
83
+ resize_exactly_to: false,
84
+ resize_gte_to: false,
85
+ size: 300 # Adjust size as needed
86
+ )
87
+ png.to_s
88
+ else
89
+ raise ArgumentError, "Unsupported mode: #{mode}. Use :svg or :png."
90
+ end
34
91
  end
35
92
 
36
- private
37
-
38
93
  def upi_content
39
94
  # Manually construct the UPI URI string without URI::UPI
40
95
  query_string = URI.encode_www_form(params)
@@ -43,5 +98,4 @@ module Upi
43
98
  end
44
99
 
45
100
  class Error < StandardError; end
46
- # Your code goes here...
47
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faraz Noor
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chunky_png
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rqrcode
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +73,7 @@ metadata:
59
73
  allowed_push_host: https://rubygems.org
60
74
  homepage_uri: https://github.com/stingrayzboy/upi
61
75
  source_code_uri: https://github.com/stingrayzboy/upi
62
- changelog_uri: https://github.com/stingrayzboy/upi/blob/main/CHANGELOG.md
76
+ changelog_uri: https://github.com/stingrayzboy/upi/blob/master/CHANGELOG.md
63
77
  post_install_message:
64
78
  rdoc_options: []
65
79
  require_paths: