qpay-rails 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7767296ec61fadc425f9c4f83b9645e464c79407e85e7b6b5783777601b5fd73
4
+ data.tar.gz: c20862358e7e1ea2633e9185988d832c46d5d325a23a799ac180ca9a32b29ddb
5
+ SHA512:
6
+ metadata.gz: 5a28a1e6d830189263d1945437578f6a3c8ea935094131120594ff176481b64cdf21026cbcc1e01bff294825727921aa60b449f11ab68e2eccc74da11d783685
7
+ data.tar.gz: 6f5e9a3a5ec53f4fdcc1211c1aedbbfe828ef9919edc6da0b1fa6107a9a36a9359484c38f492e70be9770313a4326e518540c279196169a81b759b6a577df284
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 QPay SDK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # QPay Rails
2
+
3
+ QPay V2 payment integration for Rails.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem "qpay-rails"
9
+ ```
10
+
11
+ ```bash
12
+ rails generate qpay:install
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ client = QPay::Rails.client
19
+ invoice = client.create_simple_invoice(
20
+ invoice_code: "YOUR_CODE",
21
+ sender_invoice_no: "ORDER-001",
22
+ amount: 10000,
23
+ callback_url: "https://yoursite.com/qpay/webhooks"
24
+ )
25
+ ```
26
+
27
+ ## View Helpers
28
+
29
+ ```erb
30
+ <%= qpay_qr_code(invoice.qr_image) %>
31
+ <%= qpay_payment_links(invoice.urls) %>
32
+ ```
33
+
34
+ ## Webhook
35
+
36
+ Subscribe to payment events:
37
+
38
+ ```ruby
39
+ ActiveSupport::Notifications.subscribe("payment_received.qpay") do |_name, _start, _finish, _id, payload|
40
+ invoice_id = payload[:invoice_id]
41
+ # handle payment
42
+ end
43
+ ```
44
+
45
+ ## License
46
+
47
+ MIT
@@ -0,0 +1,32 @@
1
+ module QPay
2
+ class WebhooksController < ActionController::API
3
+ def create
4
+ invoice_id = params[:invoice_id]
5
+
6
+ unless invoice_id.present?
7
+ render json: { error: "Missing invoice_id" }, status: :bad_request
8
+ return
9
+ end
10
+
11
+ begin
12
+ client = QPay::Rails.client
13
+ result = client.check_payment(
14
+ object_type: "INVOICE",
15
+ object_id: invoice_id
16
+ )
17
+
18
+ if result.rows&.any?
19
+ ActiveSupport::Notifications.instrument("payment_received.qpay", {
20
+ invoice_id: invoice_id,
21
+ result: result
22
+ })
23
+ render json: { status: "paid" }
24
+ else
25
+ render json: { status: "unpaid" }
26
+ end
27
+ rescue StandardError => e
28
+ render json: { error: e.message }, status: :internal_server_error
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ module QPayHelper
2
+ def qpay_qr_code(qr_image, size: 256)
3
+ return "" if qr_image.blank?
4
+ content_tag(:div, class: "qpay-qr-code", style: "text-align:center;") do
5
+ image_tag("data:image/png;base64,#{qr_image}", alt: "QPay QR Code", width: size, height: size)
6
+ end
7
+ end
8
+
9
+ def qpay_payment_links(urls)
10
+ return "" if urls.blank?
11
+ content_tag(:div, style: "display:flex;flex-wrap:wrap;gap:8px;justify-content:center;") do
12
+ safe_join(urls.map { |link|
13
+ link_to(link[:link] || link["link"] || "#", target: "_blank",
14
+ style: "display:inline-flex;align-items:center;gap:6px;padding:10px 16px;border:1px solid #ddd;border-radius:8px;text-decoration:none;color:#333;font-size:14px;") do
15
+ logo = link[:logo] || link["logo"]
16
+ name = link[:name] || link["name"] || "Pay"
17
+ parts = []
18
+ parts << image_tag(logo, width: 24, height: 24, alt: name) if logo.present?
19
+ parts << name
20
+ safe_join(parts)
21
+ end
22
+ })
23
+ end
24
+ end
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ QPay::Rails::Engine.routes.draw do
2
+ post "webhooks", to: "webhooks#create"
3
+ end
@@ -0,0 +1,24 @@
1
+ module Qpay
2
+ class InstallGenerator < ::Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+ desc "Install QPay payment integration"
5
+
6
+ def copy_initializer
7
+ template "initializer.rb", "config/initializers/qpay.rb"
8
+ end
9
+
10
+ def add_route
11
+ route 'mount QPay::Rails::Engine => "/qpay"'
12
+ end
13
+
14
+ def show_instructions
15
+ say ""
16
+ say "QPay installed! Set these environment variables:", :green
17
+ say " QPAY_BASE_URL=https://merchant.qpay.mn"
18
+ say " QPAY_USERNAME=your_username"
19
+ say " QPAY_PASSWORD=your_password"
20
+ say " QPAY_INVOICE_CODE=your_invoice_code"
21
+ say " QPAY_CALLBACK_URL=https://yoursite.com/qpay/webhooks"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ QPay::Rails.configure do |config|
2
+ config.base_url = ENV.fetch("QPAY_BASE_URL", "https://merchant.qpay.mn")
3
+ config.username = ENV.fetch("QPAY_USERNAME")
4
+ config.password = ENV.fetch("QPAY_PASSWORD")
5
+ config.invoice_code = ENV.fetch("QPAY_INVOICE_CODE")
6
+ config.callback_url = ENV.fetch("QPAY_CALLBACK_URL")
7
+ end
@@ -0,0 +1,29 @@
1
+ module QPay
2
+ module Rails
3
+ class Client
4
+ class << self
5
+ def instance
6
+ @instance ||= build_client
7
+ end
8
+
9
+ def reset!
10
+ @instance = nil
11
+ end
12
+
13
+ private
14
+
15
+ def build_client
16
+ cfg = QPay::Rails.configuration
17
+ config = QPay::Config.new(
18
+ base_url: cfg.base_url,
19
+ username: cfg.username,
20
+ password: cfg.password,
21
+ invoice_code: cfg.invoice_code,
22
+ callback_url: cfg.callback_url
23
+ )
24
+ QPay::Client.new(config: config)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module QPay
2
+ module Rails
3
+ class Configuration
4
+ attr_accessor :base_url, :username, :password, :invoice_code, :callback_url
5
+
6
+ def initialize
7
+ @base_url = ENV.fetch("QPAY_BASE_URL", "https://merchant.qpay.mn")
8
+ @username = ENV["QPAY_USERNAME"]
9
+ @password = ENV["QPAY_PASSWORD"]
10
+ @invoice_code = ENV["QPAY_INVOICE_CODE"]
11
+ @callback_url = ENV["QPAY_CALLBACK_URL"]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module QPay
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace QPay::Rails
5
+
6
+ initializer "qpay.helpers" do
7
+ ActiveSupport.on_load(:action_view) do
8
+ require "qpay_helper"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module QPay
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
data/lib/qpay/rails.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "qpay"
2
+ require "qpay/rails/version"
3
+ require "qpay/rails/configuration"
4
+ require "qpay/rails/client"
5
+ require "qpay/rails/engine"
6
+
7
+ module QPay
8
+ module Rails
9
+ class << self
10
+ attr_writer :configuration
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield(configuration)
18
+ end
19
+
20
+ def client
21
+ Client.instance
22
+ end
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qpay-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - QPay SDK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: qpay
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ description: Rails engine for QPay V2 payment API with view helpers and webhook support
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - app/controllers/qpay/webhooks_controller.rb
50
+ - app/helpers/qpay_helper.rb
51
+ - config/routes.rb
52
+ - lib/generators/qpay/install_generator.rb
53
+ - lib/generators/qpay/templates/initializer.rb
54
+ - lib/qpay/rails.rb
55
+ - lib/qpay/rails/client.rb
56
+ - lib/qpay/rails/configuration.rb
57
+ - lib/qpay/rails/engine.rb
58
+ - lib/qpay/rails/version.rb
59
+ homepage: https://github.com/qpay-sdk/qpay-rails
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '3.0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.4.19
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: QPay V2 payment integration for Rails
82
+ test_files: []