parsbank 0.0.5 → 0.0.9
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/README.md +9 -24
- data/lib/db_setup.rb +103 -0
- data/lib/locales/en.yml +18 -0
- data/lib/locales/fa.yml +19 -0
- data/lib/parsbank/{bsc-bitcoin/bsc-bitcoin.rb → binance/binance.rb} +2 -1
- data/lib/parsbank/gates.rb +16 -0
- data/lib/parsbank/mellat/logo.svg +1 -0
- data/lib/parsbank/mellat/mellat.rb +2 -6
- data/lib/parsbank/restfull.rb +35 -23
- data/lib/parsbank/soap.rb +106 -0
- data/lib/parsbank/transaction_request.rb +134 -0
- data/lib/parsbank/transaction_verify.rb +135 -0
- data/lib/parsbank/version.rb +1 -1
- data/lib/parsbank.rb +25 -185
- data/lib/tmpl/_loader.html.erb +105 -0
- metadata +13 -24
- data/lib/parsbank/nobitex/nobitex.rb +0 -150
- data/lib/parsbank/zarinpal/logo.svg +0 -56
- data/lib/parsbank/zarinpal/zarinpal.rb +0 -111
- data/lib/parsbank/zibal/logo.svg +0 -42
- data/lib/parsbank/zibal/zibal.rb +0 -150
- data/lib/psp.json +0 -78
- /data/lib/parsbank/{bsc-bitcoin/bsc-bitcoin.svg → binance/logo.svg} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e06108ffa9e0ff32ba436f8d1122529e61780965176c94a0553a84b8d73123c
|
|
4
|
+
data.tar.gz: 16ea88dbd6ddcf8daed720b568d184857348f72866fd606542f1bb9747d177ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 02dd5ddb88e6594a41518e3d85a8edac46d6baac8622bd293381425eb16880baba198aaf2240905bfaf0b5f2279b1c89c0cb061a1ece102ca357d6355eac824b
|
|
7
|
+
data.tar.gz: 10342d63171df90e125cc543c8dffee84a0958d31b0a9be19a27169f3bec10512b75550caf6802dc7ae538ae0ddf4f981b3a3f1cc739e88afc5b7adcb72b180f
|
data/README.md
CHANGED
|
@@ -54,7 +54,7 @@ ParsBank.configuration do |config|
|
|
|
54
54
|
config.mitm_server = 'https://your-mitm-server.com' # MITM server location
|
|
55
55
|
config.secrets_path = Rails.root.join('config/bank_secrets.yaml') # Path to bank credentials (e.g., merchant ID, tokens)
|
|
56
56
|
|
|
57
|
-
# Web Panel Configuration
|
|
57
|
+
# Web Panel Configuration For Pro Users
|
|
58
58
|
config.webpanel_path = '/parsbank' # Web panel path
|
|
59
59
|
config.username = ENV['PARSBANK_USERNAME'] # Web panel username
|
|
60
60
|
config.password = ENV['PARSBANK_PASSWORD'] # Web panel password
|
|
@@ -80,12 +80,12 @@ class CartController < ApplicationController
|
|
|
80
80
|
# @INPUT crypto_amount: can be crypto assets amount like 0.0005
|
|
81
81
|
# @INPUT real_amount: When use crypto or Rials can use dollar instead amount of crypto (E.G 100 dollar equal 0.005 bitcoin)
|
|
82
82
|
# @INPUT description(required): Explain transaction details
|
|
83
|
-
# @INPUT bank: Select specific bank or payment method like 'bsc-binance', '
|
|
83
|
+
# @INPUT bank: Select specific bank or payment method like 'bsc-binance', 'perfect-money'
|
|
84
84
|
# @INPUT tags: Used for call which payments method such as ['crypto','rls','dollar','persian-banks','russian-banks']
|
|
85
85
|
# @OUTPUT get_redirect_from: an javascript code for redirect user to gateways
|
|
86
86
|
def redirect_to_parsbank
|
|
87
|
-
form = ParsBank.
|
|
88
|
-
render html:
|
|
87
|
+
form = ParsBank.transaction_request(fiat_amount: '10', description: 'Charge Account')
|
|
88
|
+
render html: from.html_form
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
# @DESC: Shortcode for get all of enabled paymetns methods
|
|
@@ -93,6 +93,8 @@ class CartController < ApplicationController
|
|
|
93
93
|
# @OUTPUT gateways_list_shortcode: List of all banks with name and logo with ul wrapper as html
|
|
94
94
|
def choose_payment
|
|
95
95
|
@payments_list_available_shortcode = ParsBank.gateways_list_shortcode
|
|
96
|
+
# ..OR..
|
|
97
|
+
@available_gateways_list = ParsBank.Parsbank.available_gateways_list
|
|
96
98
|
end
|
|
97
99
|
|
|
98
100
|
# @DESC: Parse all returned params from banks for verify transaction
|
|
@@ -153,17 +155,7 @@ We currently do not accept pull requests. Please report any issues in the [GitHu
|
|
|
153
155
|
|
|
154
156
|
## 💖 Support This Project
|
|
155
157
|
|
|
156
|
-
If you find this project helpful and would like to support its development, consider making a donation. Your contributions help maintain and improve this project.
|
|
157
|
-
|
|
158
|
-
### Donate USDT (Tether)
|
|
159
|
-
- **USDT (ERC-20):** `0x2028f409a42413076665231e209896bbe0221d64`
|
|
160
|
-
- **USDT (TRC-20):** `TNtLkdy2FAKKBGJ4F8ij2mppWpjkB8GULy`
|
|
161
|
-
- **USDT (BEP-20):** `0x2028f409a42413076665231e209896bbe0221d64`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
### Donate BTC (Bitcoin)
|
|
165
|
-
- **BSC (BEP-20):** `0x2028f409a42413076665231e209896bbe0221d64`
|
|
166
|
-
|
|
158
|
+
If you find this project helpful and would like to support its development, consider making a donation. Your contributions help maintain and improve this project.
|
|
167
159
|
|
|
168
160
|
|
|
169
161
|
## 🚀 Premium Features
|
|
@@ -172,15 +164,8 @@ This project offers **premium features** to enhance your experience and support
|
|
|
172
164
|
|
|
173
165
|
#### 🔐 How to Access Premium Features
|
|
174
166
|
1. **Make a Contribution**:
|
|
175
|
-
-
|
|
176
|
-
|
|
177
|
-
- Email your transaction details to `info@abrfa.net` or submit them via a dedicated contact form.
|
|
178
|
-
3. **Receive Access**:
|
|
179
|
-
- Upon verification, you'll receive instructions to access the premium features.
|
|
180
|
-
|
|
181
|
-
#### 💳 USDT Wallet Addresses
|
|
182
|
-
- **USDT (ERC-20):** `0x2028f409a42413076665231e209896bbe0221d64`
|
|
183
|
-
- **USDT (TRC-20):** `TNtLkdy2FAKKBGJ4F8ij2mppWpjkB8GULy`
|
|
167
|
+
- Follow and take features request to one of the github below(Annualy).
|
|
168
|
+
|
|
184
169
|
|
|
185
170
|
#### 🔥 Available Premium Features
|
|
186
171
|
- Feature 1: **Advanced Analytics**
|
data/lib/db_setup.rb
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Parsbank
|
|
4
|
+
class DBSetup
|
|
5
|
+
def self.establish_connection
|
|
6
|
+
if Parsbank.configuration.database_url.present?
|
|
7
|
+
setup_db
|
|
8
|
+
else
|
|
9
|
+
simulate_db
|
|
10
|
+
puts("\033[31mParsBank ERROR: database_url not set, Transaction history not stored on database\033[0m")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.simulate_db
|
|
15
|
+
model_name = Parsbank.configuration.model || 'Transaction'
|
|
16
|
+
simulated_model = Class.new do
|
|
17
|
+
attr_accessor :description, :amount, :gateway, :callback_url, :status,
|
|
18
|
+
:user_id, :cart_id, :local_id, :ip, :gateway_verify_response, :gateway_response, :track_id, :unit, :created_at, :updated_at
|
|
19
|
+
|
|
20
|
+
def initialize(attributes = {})
|
|
21
|
+
build_attrs attributes.merge({created_at: Time.now})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update!(attributes = {})
|
|
25
|
+
build_attrs attributes.merge({updated_at: Time.now})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def build_attrs attributes = {}
|
|
29
|
+
attributes.each do |key, value|
|
|
30
|
+
send("#{key}=", value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
def save
|
|
34
|
+
# Simulate saving (e.g., print or log the data)
|
|
35
|
+
@id = Time.now.to_i # Simulate an ID assignment
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
attr_reader :id
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Set the simulated class as a constant
|
|
43
|
+
Object.const_set(model_name.camelcase, simulated_model)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.setup_db
|
|
47
|
+
database_url = Parsbank.configuration.database_url
|
|
48
|
+
model = Parsbank.configuration.model
|
|
49
|
+
raise 'DATABASE_URL environment variable is not set' if database_url.nil?
|
|
50
|
+
|
|
51
|
+
supported_databases = {
|
|
52
|
+
'postgresql' => 'pg',
|
|
53
|
+
'mysql2' => 'mysql2',
|
|
54
|
+
'sqlite3' => 'sqlite3',
|
|
55
|
+
'nulldb' => 'nulldb'
|
|
56
|
+
}.freeze
|
|
57
|
+
|
|
58
|
+
uri = URI.parse(database_url)
|
|
59
|
+
|
|
60
|
+
gem_name = supported_databases[uri.scheme]
|
|
61
|
+
unless gem_name
|
|
62
|
+
raise "Unsupported database adapter: #{uri.scheme}. Supported adapters: #{supported_databases.keys.join(', ')}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
require gem_name
|
|
67
|
+
rescue LoadError
|
|
68
|
+
raise "Missing required gem for #{uri.scheme}. Please add `gem '#{gem_name}'` to your Gemfile."
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
begin
|
|
72
|
+
ActiveRecord::Base.establish_connection(database_url)
|
|
73
|
+
unless ActiveRecord::Base.connection.table_exists?(model.tableize)
|
|
74
|
+
puts 'Create Transaction Table'
|
|
75
|
+
ActiveRecord::Base.connection.create_table model.tableize do |t|
|
|
76
|
+
t.string :gateway
|
|
77
|
+
t.string :amount
|
|
78
|
+
t.string :unit
|
|
79
|
+
t.string :track_id
|
|
80
|
+
t.string :local_id
|
|
81
|
+
t.string :ip
|
|
82
|
+
t.integer :user_id
|
|
83
|
+
t.integer :cart_id
|
|
84
|
+
t.text :description
|
|
85
|
+
t.string :callback_url
|
|
86
|
+
t.text :gateway_verify_response
|
|
87
|
+
t.text :gateway_response
|
|
88
|
+
t.string :status
|
|
89
|
+
t.timestamps
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
unless Object.const_defined?(model)
|
|
94
|
+
Object.const_set(model, Class.new(ActiveRecord::Base) do
|
|
95
|
+
self.table_name = model.tableize
|
|
96
|
+
end)
|
|
97
|
+
end
|
|
98
|
+
rescue StandardError => e
|
|
99
|
+
raise "Failed to connect to the database: #{e.message}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/locales/en.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
en:
|
|
2
|
+
actions:
|
|
3
|
+
redirect_to_gate: "You are being redirected to the payment gateway..."
|
|
4
|
+
success: "The operation was successful"
|
|
5
|
+
failed: "The operation encountered an error"
|
|
6
|
+
uncertain: "The operation status is temporarily uncertain"
|
|
7
|
+
bank_names:
|
|
8
|
+
nobitex: "Nobitex"
|
|
9
|
+
mellat: "Mellat Bank"
|
|
10
|
+
zarinpal: "Zarinpal"
|
|
11
|
+
zibal: "Zibal"
|
|
12
|
+
binance: "Binance"
|
|
13
|
+
bank_list:
|
|
14
|
+
nobitex: "You are making a cryptocurrency payment through the Nobitex gateway. Please note that you can use two methods: Tether (USDT-TRC20) and Bitcoin (BTC-Lightning)."
|
|
15
|
+
zarinpal: "You are making a payment through the Zarinpal gateway."
|
|
16
|
+
mellat: "You are making a payment through the Mellat Bank direct payment gateway."
|
|
17
|
+
zibal: "You are making a payment through the Zibal gateway."
|
|
18
|
+
binance: "You are making a cryptocurrency payment through Binance."
|
data/lib/locales/fa.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
fa:
|
|
2
|
+
actions:
|
|
3
|
+
redirect_to_gate: "در حال انتقال به درگاه پرداخت هستید"
|
|
4
|
+
success: "عملیات با موفقیت انجام شد"
|
|
5
|
+
failed: "عملیات با خطا مواجه شد"
|
|
6
|
+
uncertain: "به طور موقت وضعیت عملیات نامشخص است"
|
|
7
|
+
bank_names:
|
|
8
|
+
nobitex: "نوبیتکس"
|
|
9
|
+
mellat: "بانک ملت"
|
|
10
|
+
zarinpal: "زرینپال"
|
|
11
|
+
zibal: "زیبال"
|
|
12
|
+
binance: "بایننس"
|
|
13
|
+
bank_list:
|
|
14
|
+
nobitex: " شما درحال پرداخت کریپتویی از طریق درگاه پرداخت نوبیتکس میباشید, توجه داشته باشید که شما میتوانید از دو روش تتر(USDT-TRC20) و بیت کوین(BTC-lightcoin) استفاده کنید"
|
|
15
|
+
zarinpal: "شما در حال پراخت با درگاه زرین پال میباشید"
|
|
16
|
+
mellat: "شما در حال پرداخت با درگاه پرداخت مستقیم بانک ملت میباشید"
|
|
17
|
+
zibal: "شما در حال پرداخت با درگاه زیبال میباشید"
|
|
18
|
+
binance: "شما در حال پرداخت پرداخت کریپتویی از طریق بایننس میباشید"
|
|
19
|
+
|
|
@@ -4,7 +4,7 @@ require 'openssl'
|
|
|
4
4
|
require 'base64'
|
|
5
5
|
|
|
6
6
|
module Parsbank
|
|
7
|
-
class
|
|
7
|
+
class Binance < Gates
|
|
8
8
|
|
|
9
9
|
attr_accessor :api_key, :secret_key, :endpoint
|
|
10
10
|
|
|
@@ -18,6 +18,7 @@ module Parsbank
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
# Generate a payment address for a given cryptocurrency
|
|
22
23
|
def generate_payment_address(asset:, network: nil)
|
|
23
24
|
endpoint = '/sapi/v1/capital/deposit/address'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Parsbank
|
|
2
|
+
class Gates
|
|
3
|
+
def self.logo
|
|
4
|
+
File.read "#{__dir__}/#{self.class.name.split('::').last.downcase}/logo.svg"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def default_config(key)
|
|
8
|
+
Parsbank.load_secrets_yaml[self.class.name.split('::').last.downcase][key.to_s]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def redirect_loaders(&block)
|
|
12
|
+
content = block_given? ? block.call : ''
|
|
13
|
+
ERB.new(File.read("#{__dir__}/../tmpl/_loader.html.erb")).result(binding).gsub(/\s+/, ' ').strip
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve" enable-background="new 0 0 190 190" viewBox="15 0 190 180"><g><radialGradient id="SVGID_1_" cx="102.0404663" cy="41.313755" r="37.7397079" fx="78.5114517" fy="20.3117523" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#FFFFFF"></stop><stop offset="0.0255132" style="stop-color:#FDF8F8"></stop><stop offset="0.2973083" style="stop-color:#EEADB4"></stop><stop offset="0.5401202" style="stop-color:#E1717E"></stop><stop offset="0.745488" style="stop-color:#D94657"></stop><stop offset="0.9052967" style="stop-color:#D32C3F"></stop><stop offset="1" style="stop-color:#D12236"></stop></radialGradient><path fill-rule="evenodd" clip-rule="evenodd" fill="url(#SVGID_1_)" stroke="#AA1F00" stroke-width="3" d=" M154.9982605,35.2635803v17.4064026l-44.9999542-25.9817524c-2-1.154747-4.5000381,0.2886276-4.5000381,2.5980511v30.0937233 c-14.4299927,2.1699829-25.5,14.6199951-25.5,29.6599731c0,3.8600464,0.7299805,7.5400391,2.0700073,10.9299927 l-17.0700073,9.8500366v-74.556427c0-3.5727024,1.9060364-6.8740082,5.0001068-8.6603203l35-20.2066498 c3.093956-1.7862411,6.9058228-1.7862411,9.9997787,0l35,20.2066498 C153.0922241,28.3895721,154.9982605,31.6908779,154.9982605,35.2635803z"></path><path fill="#D12236" stroke="#AA1F00" stroke-width="3" d="M40.9271736,76.959938l15.0739479-8.7032013v51.9619827 c-0.0000381,2.3094254,2.4995384,3.7528381,4.4995613,2.5981293l26.061924-15.0468674 c9.0942612,11.4117508,25.411293,14.7736511,38.4362946,7.2536621c3.3428955-1.9300232,6.1648712-4.4021988,8.4306488-7.2576752 l17.0653839,9.8580475l-64.5677567,37.2782059c-3.0940552,1.7863617-6.9060898,1.7863312-10.0001144-0.000061 l-34.9994774-20.2075653c-3.0939064-1.7863159-5.000103-5.0874939-5.0001488-8.6600571V85.6203232 C35.9273911,82.0476227,37.8331223,78.7462921,40.9271736,76.959938z"></path><path fill="#D12236" stroke="#AA1F00" stroke-width="3" d="M134.0728302,154.9002228l-15.0743942-8.7032013l45.0008316-25.9802322 c2.0000458-1.1546783,2.0000763-4.0414658,0.0000458-5.1961746l-26.0619202-15.0468597 c5.3357391-13.5817337,0.0887146-29.3936462-12.9362946-36.9136391c-3.3428955-1.9300232-6.8925476-3.1378365-10.4983444-3.6723137 V39.6797218l64.570076,37.2782173c3.0940399,1.7863464,4.9997864,5.087677,4.9997253,8.6603775v40.4142151 c-0.0000458,3.5725708-1.9062347,6.8737335-5.0001373,8.6600647l-34.9994812,20.2075653 C140.9789124,156.686554,137.1668701,156.6865692,134.0728302,154.9002228z"></path><linearGradient id="SVGID_00000119836251559533381810000007217859948108605595_" gradientUnits="userSpaceOnUse" x1="134.7217255" y1="114.6244202" x2="96.320816" y2="74.8863297"><stop offset="0.0811578" style="stop-color:#FFD88B"></stop><stop offset="0.3899239" style="stop-color:#FFD667"></stop><stop offset="0.7925526" style="stop-color:#FFD33E"></stop><stop offset="1" style="stop-color:#FFD22E"></stop></linearGradient><circle fill="url(#SVGID_00000119836251559533381810000007217859948108605595_)" stroke="#FF9F00" stroke-width="3.5" cx="109.9994202" cy="89.0412445" r="21"></circle></g></svg>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Parsbank
|
|
2
|
-
class Mellat
|
|
2
|
+
class Mellat < Gates
|
|
3
3
|
attr_accessor :order_id, :amount, :local_date, :local_time, :additional_data, :payer_id, :callback_url
|
|
4
4
|
attr_reader :response, :status, :status_message, :ref_id
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ module Parsbank
|
|
|
18
18
|
rescue KeyError => e
|
|
19
19
|
raise ArgumentError, "Missing required argument: #{e.message}"
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
def validate(response = nil)
|
|
23
23
|
@response = response
|
|
24
24
|
perform_validation
|
|
@@ -65,10 +65,6 @@ function postRefId (refIdValue) {
|
|
|
65
65
|
|
|
66
66
|
private
|
|
67
67
|
|
|
68
|
-
def default_config(key)
|
|
69
|
-
Parsbank.load_secrets_yaml[self.class.name.split("::").last.downcase][key.to_s]
|
|
70
|
-
end
|
|
71
|
-
|
|
72
68
|
def create_wsdl_client
|
|
73
69
|
Savon.client(
|
|
74
70
|
wsdl: default_config(:wsdl) || 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl',
|
data/lib/parsbank/restfull.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'net/http'
|
|
2
4
|
require 'uri'
|
|
3
5
|
require 'json'
|
|
@@ -7,7 +9,7 @@ module Parsbank
|
|
|
7
9
|
attr_accessor :connection
|
|
8
10
|
|
|
9
11
|
MAX_RETRIES = 3
|
|
10
|
-
RETRY_INTERVAL =
|
|
12
|
+
RETRY_INTERVAL = 5 # In seconds
|
|
11
13
|
|
|
12
14
|
def initialize(args = {})
|
|
13
15
|
@endpoint = args.fetch(:endpoint)
|
|
@@ -22,6 +24,7 @@ module Parsbank
|
|
|
22
24
|
|
|
23
25
|
def call
|
|
24
26
|
response = send_request
|
|
27
|
+
|
|
25
28
|
log_response(response)
|
|
26
29
|
|
|
27
30
|
if response.is_a?(Net::HTTPSuccess)
|
|
@@ -40,8 +43,9 @@ module Parsbank
|
|
|
40
43
|
def setup_connection
|
|
41
44
|
@uri = URI.parse(@endpoint)
|
|
42
45
|
@connection = Net::HTTP.new(@uri.host, @uri.port)
|
|
43
|
-
@connection.use_ssl =
|
|
44
|
-
|
|
46
|
+
@connection.use_ssl = @uri.scheme == 'https'
|
|
47
|
+
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
48
|
+
@connection.set_debug_output($stdout) if Parsbank.configuration.debug
|
|
45
49
|
# Setting timeouts
|
|
46
50
|
@connection.open_timeout = 10 # Time to wait for the connection to open
|
|
47
51
|
@connection.read_timeout = 10 # Time to wait for a response
|
|
@@ -56,18 +60,16 @@ module Parsbank
|
|
|
56
60
|
|
|
57
61
|
# Handling redirects manually (max 5 redirects)
|
|
58
62
|
handle_redirects(response)
|
|
59
|
-
|
|
63
|
+
|
|
60
64
|
return response
|
|
61
65
|
end
|
|
62
66
|
rescue Timeout::Error => e
|
|
63
67
|
retries += 1
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
raise "Request timed out after #{MAX_RETRIES} retries: #{e.message}"
|
|
70
|
-
end
|
|
68
|
+
raise "Request timed out after #{MAX_RETRIES} retries: #{e.message}" unless retries < MAX_RETRIES
|
|
69
|
+
|
|
70
|
+
log_to_rails("Timeout occurred. Retrying... (#{retries}/#{MAX_RETRIES})", :warn)
|
|
71
|
+
sleep(RETRY_INTERVAL)
|
|
72
|
+
retry
|
|
71
73
|
rescue StandardError => e
|
|
72
74
|
log_to_rails("Request failed: #{e.message}", :error)
|
|
73
75
|
raise e
|
|
@@ -89,7 +91,10 @@ module Parsbank
|
|
|
89
91
|
|
|
90
92
|
def build_post_request
|
|
91
93
|
request = Net::HTTP::Post.new(@action, default_headers)
|
|
92
|
-
request
|
|
94
|
+
request['Connection'] = 'close' # Avoid HTTP/2 issues
|
|
95
|
+
request.body = JSON.generate(@request_message) if @request_message.any?
|
|
96
|
+
puts "Request Header: #{default_headers}" if Parsbank.configuration.debug
|
|
97
|
+
puts "Request Body: #{request.body}" if Parsbank.configuration.debug
|
|
93
98
|
request
|
|
94
99
|
end
|
|
95
100
|
|
|
@@ -105,8 +110,10 @@ module Parsbank
|
|
|
105
110
|
|
|
106
111
|
def default_headers
|
|
107
112
|
{
|
|
108
|
-
'
|
|
109
|
-
'
|
|
113
|
+
'content-type' => 'application/json',
|
|
114
|
+
'accept' => 'application/json',
|
|
115
|
+
'user-agent' => 'ParsBank Ruby Gem',
|
|
116
|
+
'app-version' => Parsbank::VERSION
|
|
110
117
|
}.merge(@headers)
|
|
111
118
|
end
|
|
112
119
|
|
|
@@ -126,7 +133,9 @@ module Parsbank
|
|
|
126
133
|
end
|
|
127
134
|
|
|
128
135
|
def log_and_raise_error(response)
|
|
129
|
-
log_to_rails(
|
|
136
|
+
log_to_rails(
|
|
137
|
+
"Request to #{@endpoint}/#{@action} failed with status: #{response.code}, error: #{response.body.inspect}", :error
|
|
138
|
+
)
|
|
130
139
|
raise "API request failed with status #{response.code}: #{response.body}"
|
|
131
140
|
end
|
|
132
141
|
|
|
@@ -150,7 +159,10 @@ module Parsbank
|
|
|
150
159
|
def webhook(message)
|
|
151
160
|
webhook_url = Parsbank.configuration.webhook
|
|
152
161
|
webhook_url.gsub!('MESSAGE', message) if Parsbank.configuration.webhook_method == :get
|
|
153
|
-
|
|
162
|
+
if Parsbank.configuration.webhook_method == :get
|
|
163
|
+
webhook_url.gsub!('TITLE',
|
|
164
|
+
"Webhook of Connection Error at #{Time.now}")
|
|
165
|
+
end
|
|
154
166
|
|
|
155
167
|
uri = URI.parse(webhook_url)
|
|
156
168
|
connection = Net::HTTP.new(uri.host, uri.port)
|
|
@@ -170,13 +182,13 @@ module Parsbank
|
|
|
170
182
|
end
|
|
171
183
|
|
|
172
184
|
def handle_redirects(response)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
return unless response.is_a?(Net::HTTPRedirection)
|
|
186
|
+
|
|
187
|
+
location = response['Location']
|
|
188
|
+
log_to_rails("Redirecting to: #{location}", :warn)
|
|
189
|
+
redirect_uri = URI.parse(location)
|
|
190
|
+
request = Net::HTTP::Get.new(redirect_uri)
|
|
191
|
+
@connection.request(request)
|
|
180
192
|
end
|
|
181
193
|
end
|
|
182
194
|
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
require 'logger'
|
|
5
|
+
|
|
6
|
+
module Parsbank
|
|
7
|
+
# SOAP Client Class - Standard SOAP generation with namespaces and headers
|
|
8
|
+
class SOAP
|
|
9
|
+
attr_reader :endpoint, :namespace, :logger
|
|
10
|
+
|
|
11
|
+
# Initialize SOAP Client with endpoint, namespace, and optional logger
|
|
12
|
+
def initialize(endpoint, namespace)
|
|
13
|
+
@endpoint = URI.parse(endpoint)
|
|
14
|
+
@namespace = namespace
|
|
15
|
+
@logger = Logger.new(STDOUT)
|
|
16
|
+
@logger.level = Parsbank.configuration.debug ? Logger::DEBUG : Logger::WARN
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Main method to make a SOAP request
|
|
20
|
+
def call(action, body, headers = {})
|
|
21
|
+
log_request(action, body)
|
|
22
|
+
|
|
23
|
+
xml = build_envelope(action, body.map { |k, v| "<s:#{k}>#{v}</#{k}>" }.join(''))
|
|
24
|
+
|
|
25
|
+
http = Net::HTTP.new(@endpoint.host, @endpoint.port)
|
|
26
|
+
http.use_ssl = (@endpoint.scheme == 'https')
|
|
27
|
+
|
|
28
|
+
request = Net::HTTP::Post.new(@endpoint.request_uri)
|
|
29
|
+
request.content_type = 'text/xml; charset=utf-8'
|
|
30
|
+
request['SOAPAction'] = "#{@namespace}/#{action}"
|
|
31
|
+
request.body = xml
|
|
32
|
+
|
|
33
|
+
headers.store('Parsbank-RubyGem', Parsbank::VERSION)
|
|
34
|
+
headers.each { |key, value| request[key] = value }
|
|
35
|
+
|
|
36
|
+
begin
|
|
37
|
+
response = http.request(request)
|
|
38
|
+
log_response(response)
|
|
39
|
+
parse_response(response)
|
|
40
|
+
rescue Timeout::Error => e
|
|
41
|
+
handle_error("Request timed out", e)
|
|
42
|
+
rescue SocketError => e
|
|
43
|
+
handle_error("Network connection failed", e)
|
|
44
|
+
rescue Errno::ECONNREFUSED => e
|
|
45
|
+
handle_error("Connection refused by server", e)
|
|
46
|
+
rescue StandardError => e
|
|
47
|
+
handle_error("Unexpected error: #{e.message}", e)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# Build the SOAP XML Envelope
|
|
54
|
+
def build_envelope(action, body)
|
|
55
|
+
<<~XML
|
|
56
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
57
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
|
58
|
+
xmlns:s="#{@namespace}">
|
|
59
|
+
<soap:Header/>
|
|
60
|
+
<soap:Body>
|
|
61
|
+
<s:#{action}>
|
|
62
|
+
#{body}
|
|
63
|
+
</s:#{action}>
|
|
64
|
+
</soap:Body>
|
|
65
|
+
</soap:Envelope>
|
|
66
|
+
XML
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Parse the XML response body
|
|
70
|
+
def parse_response(response)
|
|
71
|
+
if response.is_a?(Net::HTTPSuccess)
|
|
72
|
+
puts "Response Success"
|
|
73
|
+
puts response.body
|
|
74
|
+
parse_xml(response.body)
|
|
75
|
+
else
|
|
76
|
+
{ error: "HTTP Error #{response.code}: #{response.message}" }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Convert XML to Hash
|
|
81
|
+
def parse_xml(xml)
|
|
82
|
+
begin
|
|
83
|
+
doc = REXML::Document.new(xml)
|
|
84
|
+
{ success: true, body: doc }
|
|
85
|
+
rescue REXML::ParseException => e
|
|
86
|
+
{ success: false, error: "Invalid XML response: #{e.message}" }
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Error handling and logging
|
|
91
|
+
def handle_error(message, exception)
|
|
92
|
+
@logger.error("#{message}: #{exception.message}")
|
|
93
|
+
{ success: false, error: message }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Log the SOAP request for debugging
|
|
97
|
+
def log_request(action, body)
|
|
98
|
+
@logger.debug("Sending SOAP request: Action = #{action}, Body = #{body}")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Log the SOAP response for debugging
|
|
102
|
+
def log_response(response)
|
|
103
|
+
@logger.debug("Received SOAP response: Status = #{response.code}, Body = #{response.body}")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
module Parsbank
|
|
2
|
+
class TransactionRequest
|
|
3
|
+
def self.create(args = {})
|
|
4
|
+
bank = fetch_bank(args)
|
|
5
|
+
validate_bank(bank)
|
|
6
|
+
|
|
7
|
+
description = args.fetch(:description)
|
|
8
|
+
callback_url = generate_callback_url(bank, description)
|
|
9
|
+
|
|
10
|
+
crypto_amount, fiat_amount, real_amount = fetch_amounts(args)
|
|
11
|
+
validate_amounts(bank, crypto_amount, fiat_amount, real_amount)
|
|
12
|
+
|
|
13
|
+
transaction = initialize_transaction(args, description, fiat_amount, crypto_amount, bank, callback_url)
|
|
14
|
+
process_gateway(bank, transaction, description, callback_url, crypto_amount, fiat_amount, args)
|
|
15
|
+
|
|
16
|
+
{ transaction: transaction, html_form: @result }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.fetch_bank(args)
|
|
20
|
+
args.fetch(:bank, Parsbank.available_gateways_list.keys.sample)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.validate_bank(bank)
|
|
24
|
+
selected_bank = Parsbank.available_gateways_list[bank]
|
|
25
|
+
raise "Bank not enabled or not exists in #{Parsbank.configuration.secrets_path}: #{bank}" unless selected_bank
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.generate_callback_url(bank, _description)
|
|
29
|
+
selected_bank = Parsbank.available_gateways_list[bank]
|
|
30
|
+
"#{selected_bank['callback_url'] || Parsbank.configuration.callback_url}&bank_name=#{bank}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.fetch_amounts(args)
|
|
34
|
+
[
|
|
35
|
+
args.fetch(:crypto_amount, nil),
|
|
36
|
+
args.fetch(:fiat_amount, nil),
|
|
37
|
+
args.fetch(:real_amount, nil)
|
|
38
|
+
]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.validate_amounts(bank, crypto_amount, fiat_amount, real_amount)
|
|
42
|
+
raise 'Amount fields are empty: crypto_amount OR fiat_amount OR real_amount' if [crypto_amount, fiat_amount,
|
|
43
|
+
real_amount].all?(&:nil?)
|
|
44
|
+
|
|
45
|
+
tags = Parsbank.supported_psp[bank]['tags']
|
|
46
|
+
if tags.include?('crypto') && crypto_amount.nil? && real_amount.nil?
|
|
47
|
+
raise "#{bank} needs crypto_amount or real_amount"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
return unless tags.include?('rial') && fiat_amount.nil? && real_amount.nil?
|
|
51
|
+
|
|
52
|
+
raise "#{bank} needs fiat_amount or real_amount"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.initialize_transaction(args, description, fiat_amount, crypto_amount, bank, callback_url)
|
|
56
|
+
model_class = Parsbank.configuration.model || 'Transaction'
|
|
57
|
+
@transaction= Object.const_get(model_class).new(
|
|
58
|
+
description: description,
|
|
59
|
+
amount: fiat_amount || crypto_amount,
|
|
60
|
+
gateway: bank,
|
|
61
|
+
callback_url: callback_url,
|
|
62
|
+
status: 'start',
|
|
63
|
+
user_id: args.fetch(:user_id, nil),
|
|
64
|
+
cart_id: args.fetch(:cart_id, nil),
|
|
65
|
+
local_id: args.fetch(:local_id, nil),
|
|
66
|
+
ip: args.fetch(:ip, nil)
|
|
67
|
+
)
|
|
68
|
+
@transaction.save
|
|
69
|
+
|
|
70
|
+
@transaction
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.process_gateway(bank, transaction, description, callback_url, crypto_amount, fiat_amount, args)
|
|
74
|
+
case bank
|
|
75
|
+
when 'mellat'
|
|
76
|
+
process_mellat(transaction, description, callback_url, fiat_amount)
|
|
77
|
+
when 'zarinpal'
|
|
78
|
+
process_zarinpal(transaction, description, callback_url, fiat_amount)
|
|
79
|
+
when 'zibal'
|
|
80
|
+
process_zibal(description, callback_url, fiat_amount)
|
|
81
|
+
when 'bscbitcoin'
|
|
82
|
+
process_bscbitcoin(transaction, description, crypto_amount, args)
|
|
83
|
+
else
|
|
84
|
+
raise "Unsupported gateway: #{bank}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.process_mellat(transaction, description, callback_url, fiat_amount)
|
|
89
|
+
mellat = Parsbank::Mellat.new(
|
|
90
|
+
amount: fiat_amount,
|
|
91
|
+
additional_data: description,
|
|
92
|
+
callback_url: callback_url,
|
|
93
|
+
orderId: transaction.id
|
|
94
|
+
)
|
|
95
|
+
mellat.call
|
|
96
|
+
transaction.update!(gateway_response: mellat.response, unit: 'irr')
|
|
97
|
+
@result = mellat.redirect_form
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.process_zarinpal(transaction, description, callback_url, fiat_amount)
|
|
101
|
+
zarinpal = Parsbank::Zarinpal.new(
|
|
102
|
+
amount: fiat_amount,
|
|
103
|
+
additional_data: description,
|
|
104
|
+
callback_url: callback_url
|
|
105
|
+
)
|
|
106
|
+
zarinpal.call
|
|
107
|
+
transaction.update!(
|
|
108
|
+
gateway_response: zarinpal.response,
|
|
109
|
+
track_id: zarinpal.ref_id,
|
|
110
|
+
unit: 'irt'
|
|
111
|
+
)
|
|
112
|
+
@result = zarinpal.redirect_form
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.process_zibal(description, callback_url, fiat_amount)
|
|
116
|
+
zibal = Parsbank::Zibal.new(
|
|
117
|
+
amount: fiat_amount,
|
|
118
|
+
additional_data: description,
|
|
119
|
+
callback_url: callback_url
|
|
120
|
+
)
|
|
121
|
+
zibal.call
|
|
122
|
+
@result = zibal.redirect_form
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def self.process_bscbitcoin(transaction, description, crypto_amount, args)
|
|
126
|
+
bscbitcoin = Parsbank::BscBitcoin.new(
|
|
127
|
+
additional_data: description
|
|
128
|
+
)
|
|
129
|
+
convert_real_amount_to_assets if crypto_amount.nil? && args.key?(:real_amount)
|
|
130
|
+
@result = bscbitcoin.generate_payment_address(amount: crypto_amount)
|
|
131
|
+
transaction.update!(gateway_response: @result, unit: 'bitcoin')
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|