Class: AstroPay::Card
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
Returns the value of attribute additional_params.
-
#amount ⇒ Object
Input params.
-
#approval_code ⇒ Object
Input params.
-
#ccv ⇒ Object
Input params.
-
#exp_date ⇒ Object
Input params.
-
#invoice_num ⇒ Object
Returns the value of attribute invoice_num.
-
#number ⇒ Object
Input params.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unique_id ⇒ Object
Input params.
Attributes inherited from Model
Instance Method Summary collapse
-
#astro_curl(url, params) ⇒ Hash
Makes a request to the AstroPay API.
-
#auth_capture_transaction ⇒ Hash
Requests AstroPay to AUTHORIZE and CAPTURE a transaction at the same time (if it is possible).
-
#auth_transaction ⇒ Hash
Requests AstroPay to AUTHORIZE a transaction.
-
#calculate_control(transaction_id, amount) ⇒ String
Generates an hexadecimal code intended to be used in the checksum of the messages received.
-
#capture_transaction ⇒ Hash
Requests AstroPay to CAPTURE the previous authorized transaction.
-
#check_transaction_status ⇒ Hash
Requests AstroPay the status of a transaction.
-
#initialize(args = {}) ⇒ AstroPay::Card
constructor
Creates a new instance of [AstroPay::Card].
-
#refund_transaction ⇒ Hash
Requests AstroPay to REFUND a transaction.
-
#void_transaction ⇒ Hash
Requests AstroPay to VOID a transaction.
Methods inherited from Model
Constructor Details
#initialize(args = {}) ⇒ AstroPay::Card
Creates a new instance of [AstroPay::Card].
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/astro_pay/card.rb', line 20 def initialize(args = {}) config = AstroPay.configuration @x_login = config.card_x_login @x_trans_key = config.card_x_trans_key @sandbox = config.sandbox base_url = "https://#{'sandbox-' if @sandbox}api.astropaycard.com/" # AstroPay API version (default "2.0") @x_version = "2.0" # Field delimiter (default "|") @x_delim_char = "|" # Change to N for production @x_test_request = 'N' # Time window of a transaction with the sames values is taken as # duplicated (default 120) @x_duplicate_window = 30 @x_method = "CC" # Response format: # "string", "json", "xml" (default: string; recommended: json) @x_response_format = "json" @additional_params = Hash.new super @validator_url = "#{base_url}verif/validator" @transtatus_url = "#{base_url}verif/transtatus" end |
Instance Attribute Details
#additional_params ⇒ Object
Returns the value of attribute additional_params.
12 13 14 |
# File 'lib/astro_pay/card.rb', line 12 def additional_params @additional_params end |
#amount ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def amount @amount end |
#approval_code ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def approval_code @approval_code end |
#ccv ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def ccv @ccv end |
#exp_date ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def exp_date @exp_date end |
#invoice_num ⇒ Object
Returns the value of attribute invoice_num.
12 13 14 |
# File 'lib/astro_pay/card.rb', line 12 def invoice_num @invoice_num end |
#number ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def number @number end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
12 13 14 |
# File 'lib/astro_pay/card.rb', line 12 def transaction_id @transaction_id end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/astro_pay/card.rb', line 12 def type @type end |
#unique_id ⇒ Object
Input params
11 12 13 |
# File 'lib/astro_pay/card.rb', line 11 def unique_id @unique_id end |
Instance Method Details
#astro_curl(url, params) ⇒ Hash
Makes a request to the AstroPay API.
163 164 165 |
# File 'lib/astro_pay/card.rb', line 163 def astro_curl(url, params) AstroPay::Curl.post(url, params) end |
#auth_capture_transaction ⇒ Hash
(See #auth_transaction) to known the data sent on the request.
Requests AstroPay to AUTHORIZE and CAPTURE a transaction at the same time (if it is possible).
97 98 99 100 101 102 103 104 105 |
# File 'lib/astro_pay/card.rb', line 97 def auth_capture_transaction data = full_params.merge( 'x_unique_id' => unique_id, 'x_invoice_num' => invoice_num, 'x_type' => "AUTH_CAPTURE" ) astro_curl(@validator_url, data) end |
#auth_transaction ⇒ Hash
This method sends in the request the following data: ‘number’, AstroPay Card number (16 digits); ‘ccv’, AstroPay Card security code (CVV); ‘exp_date’, AstroPay Card expiration date; ‘amount’, Amount of the transaction; ‘unique_id’, Unique user ID of the merchant; ‘invoice_num’, Merchant transaction identifier, i.e. the order number; ‘additional_params’, Array of additional info that you would send to AstroPay for reference purpose.
Requests AstroPay to AUTHORIZE a transaction.
65 66 67 68 69 70 71 72 73 |
# File 'lib/astro_pay/card.rb', line 65 def auth_transaction data = full_params.merge( 'x_unique_id' => unique_id, 'x_invoice_num' => invoice_num, 'x_type' => "AUTH_ONLY" ) astro_curl(@validator_url, data) end |
#calculate_control(transaction_id, amount) ⇒ String
Generates an hexadecimal code intended to be used in the checksum of the messages received.
173 174 175 |
# File 'lib/astro_pay/card.rb', line 173 def calculate_control(transaction_id, amount) Digest::MD5.hexdigest("#{@x_login}#{transaction_id}#{amount}") end |
#capture_transaction ⇒ Hash
(See #auth_transaction) to known the data sent on the request.
Requests AstroPay to CAPTURE the previous authorized transaction.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/astro_pay/card.rb', line 80 def capture_transaction data = full_params.merge( 'x_unique_id' => unique_id, 'x_invoice_num' => invoice_num, 'x_auth_code' => approval_code, 'x_type' => "CAPTURE_ONLY" ) astro_curl(@validator_url, data) end |
#check_transaction_status ⇒ Hash
This request includes the basic credentials data and the following fields: ‘invoice_num’, The merchant id sent in the transaction; ‘type’, 0 for basic info, 1 for detailed info.
Requests AstroPay the status of a transaction.
147 148 149 150 151 152 153 154 155 |
# File 'lib/astro_pay/card.rb', line 147 def check_transaction_status data = basic_credentials.merge( 'x_trans_key' => @x_trans_key, 'x_invoice_num' => invoice_num, 'x_type' => (type || 0) ) astro_curl(@transtatus_url, data) end |
#refund_transaction ⇒ Hash
This request includes the transaction_id merchant invoice number sent in previous call of capture_transaction or auth_transaction. (See #auth_transaction) to known the data sent on the request.
Requests AstroPay to REFUND a transaction.
114 115 116 117 118 119 120 121 |
# File 'lib/astro_pay/card.rb', line 114 def refund_transaction data = full_params.merge( 'x_trans_id' => transaction_id, 'x_type' => "REFUND" ) astro_curl(@validator_url, data) end |
#void_transaction ⇒ Hash
This request includes the transaction_id merchant invoice number sent in previous call of capture_transaction or auth_transaction. (See #auth_transaction) to known the data sent on the request.
Requests AstroPay to VOID a transaction.
130 131 132 133 134 135 136 137 |
# File 'lib/astro_pay/card.rb', line 130 def void_transaction data = full_params.merge( 'x_trans_id' => transaction_id, 'x_type' => "VOID" ) astro_curl(@validator_url, data) end |