Class: AstroPay::Direct
Instance Attribute Summary collapse
-
#amount ⇒ Object
Input params.
-
#bank ⇒ Object
Input params.
-
#confirmation_url ⇒ Object
Returns the value of attribute confirmation_url.
-
#country ⇒ Object
Input params.
-
#cpf ⇒ Object
Returns the value of attribute cpf.
-
#currency ⇒ Object
Input params.
-
#description ⇒ Object
Returns the value of attribute description.
-
#iduser ⇒ Object
Input params.
-
#invoice ⇒ Object
Input params.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#sub_code ⇒ Object
Returns the value of attribute sub_code.
Attributes inherited from Model
Instance Method Summary collapse
-
#astro_curl(url, params_hash) ⇒ Hash
Makes a request to the AstroPay API.
-
#create ⇒ Hash
Creates a new transaction.
-
#get_banks_by_country ⇒ Hash
Requests a list of valid banks by country.
-
#get_exchange ⇒ Hash
Requests the exchange rate from USD to the currency of a target country.
-
#get_invoice_status ⇒ Hash
Requests the status of a transaction.
-
#initialize(args = {}) ⇒ AstroPay::Direct
constructor
Creates a new instance of [AstroPay::Direct].
Methods inherited from Model
Constructor Details
#initialize(args = {}) ⇒ AstroPay::Direct
Creates a new instance of [AstroPay::Direct].
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/astro_pay/direct.rb', line 21 def initialize(args = {}) config = AstroPay.configuration @x_login = config.direct_x_login @x_trans_key = config.direct_x_trans_key @x_login_for_webpaystatus = config.direct_x_login_for_webpaystatus @x_trans_key_for_webpaystatus = config.direct_x_trans_key_for_webpaystatus @secret_key = config.direct_secret_key @sandbox = config.sandbox @response_type = 'json' super subdomain = 'sandbox.' if @sandbox @astro_urls = { "create" => "https://#{subdomain}astropaycard.com/api_curl/apd/create", "status" => "https://#{subdomain}astropaycard.com/apd/webpaystatus", "exchange" => "https://#{subdomain}astropaycard.com/apd/webcurrencyexchange", "banks" => "https://#{subdomain}astropaycard.com/api_curl/apd/get_banks_by_country" } end |
Instance Attribute Details
#amount ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def amount @amount end |
#bank ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def bank @bank end |
#confirmation_url ⇒ Object
Returns the value of attribute confirmation_url.
12 13 14 |
# File 'lib/astro_pay/direct.rb', line 12 def confirmation_url @confirmation_url end |
#country ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def country @country end |
#cpf ⇒ Object
Returns the value of attribute cpf.
12 13 14 |
# File 'lib/astro_pay/direct.rb', line 12 def cpf @cpf end |
#currency ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def currency @currency end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/astro_pay/direct.rb', line 12 def description @description end |
#iduser ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def iduser @iduser end |
#invoice ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/direct.rb', line 11 def invoice @invoice end |
#response_type ⇒ Object
Returns the value of attribute response_type.
13 14 15 |
# File 'lib/astro_pay/direct.rb', line 13 def response_type @response_type end |
#return_url ⇒ Object
Returns the value of attribute return_url.
12 13 14 |
# File 'lib/astro_pay/direct.rb', line 12 def return_url @return_url end |
#sub_code ⇒ Object
Returns the value of attribute sub_code.
12 13 14 |
# File 'lib/astro_pay/direct.rb', line 12 def sub_code @sub_code end |
Instance Method Details
#astro_curl(url, params_hash) ⇒ Hash
Makes a request to the AstroPay API.
132 133 134 |
# File 'lib/astro_pay/direct.rb', line 132 def astro_curl(url, params_hash) AstroPay::Curl.post(url, params_hash) end |
#create ⇒ Hash
Creates a new transaction.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/astro_pay/direct.rb', line 49 def create params_hash = { 'x_login' => @x_login, 'x_trans_key' => @x_trans_key, 'x_invoice' => invoice, 'x_amount' => amount, 'x_iduser' => iduser, 'x_bank' => bank, 'x_country' => country, 'x_sub_code' => sub_code, 'type' => response_type } = "#{invoice}D#{amount}P#{iduser}A" sha256 = OpenSSL::Digest::SHA256.new control = OpenSSL::HMAC.hexdigest(sha256, [@secret_key].pack('A*'), [].pack('A*')) control = control.upcase params_hash['control'] = control params_hash['x_currency'] = currency if currency params_hash['x_description'] = description if description params_hash['x_cpf'] = cpf if cpf params_hash['x_return'] = return_url if return_url params_hash['x_confirmation'] = confirmation_url if confirmation_url astro_curl(@astro_urls['create'], params_hash) end |
#get_banks_by_country ⇒ Hash
Requests a list of valid banks by country.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/astro_pay/direct.rb', line 82 def get_banks_by_country params_hash = { # Mandatory 'x_login' => @x_login, 'x_trans_key' => @x_trans_key, 'country_code' => country, 'type' => response_type } astro_curl(@astro_urls['banks'], params_hash) end |
#get_exchange ⇒ Hash
Requests the exchange rate from USD to the currency of a target country.
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/astro_pay/direct.rb', line 114 def get_exchange params_hash = { # Mandatory 'x_login' => @x_login_for_webpaystatus, 'x_trans_key' => @x_trans_key_for_webpaystatus, 'x_country' => country, 'x_amount' => amount } astro_curl(@astro_urls['exchange'], params_hash) end |
#get_invoice_status ⇒ Hash
Requests the status of a transaction.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/astro_pay/direct.rb', line 98 def get_invoice_status params_hash = { # Mandatory 'x_login' => @x_login_for_webpaystatus, 'x_trans_key' => @x_trans_key_for_webpaystatus, 'x_invoice' => invoice, 'x_response_format' => response_type } astro_curl(@astro_urls['status'], params_hash) end |