lib/nitro_pay/transaction.rb in nitro_pay-1.0.0 vs lib/nitro_pay/transaction.rb in nitro_pay-1.0.1
- old
+ new
@@ -1,8 +1,9 @@
module NitroPay
# Transaction Obj, but can Abstract nested objs like Costumer
class Transaction < NitroPay::Connection
+ attr_accessor :tid
attr_accessor :resp
attr_accessor :status # can be API Status: self.status = NitroPay::Status.new OR/AND Transaction Status
attr_accessor :sold_items
# Constructor
@@ -10,36 +11,36 @@
super # super init call
# Base redirect_link if test_env is set (so the redirect is just appended)
self.redirect_link = "#{self.end_point_versioned}/transactions" if params[:test_env]
end
- # Return it RID easily
- def rid
- self.resp[:rid]
- end
-
# Return it Purchase URL, to pay on the OperatorPage
- def purchase_url
- self.resp[:purchase_url]
+ def checkout_page_url
+ hash_resp[:checkout_page]
end
- # GET /api/transactions/:rid by it attr
+ # GET /api/transactions/:tid by it attr
def verify
auth_hash = {}
+ tid = self.resp[:tid]
auth_hash[:auth] = self.request_params[:auth]
- if self.rid.nil? then return {error:'RID not received'} else self.path = "transactions/#{self.rid}/#{auth_hash.it_keys_to_get_param}" end
+ if tid.nil? then return {error:'TID not received'} else self.path = "transactions/#{tid}#{auth_hash.it_keys_to_get_param}" end
return self.get_json_request
end
+ def unformed_received_amount
+ NitroPay::Currency.to_operator_str self.hash_resp[:amount].to_s
+ end
+
# POST /api/transactions/page return operator page URL, like the Cielo Page
def charge_page(full_resp=false)
custom_http_params
# SetUp redirect dynamic if is test
self.request_params[:transaction][:redirect_link] = "#{self.redirect_link}" if self.request_params[:transaction][:test_env]
# dynamic path (it is written when a specific method use it)
- self.path = 'transactions/page'
+ self.path = 'checkouts'
# using json_request because need only the answer (do not use something like it HTTP Code)
self.resp = self.post_json_request unless full_resp
self.resp = self.post_request if full_resp
self.resp
@@ -58,66 +59,71 @@
# return it received resp
self.resp
end
# Update the recurrence amount
- def update_subscription(rid=nil, full_resp=false)
+ def update_subscription(tid=nil, full_resp=false)
# SetUp
- self.recurrent_rid = rid if rid
- self.path = "transactions/#{self.recurrent_rid}/subscription"
+ self.recurrent_tid = tid if tid
+ self.path = "transactions/#{self.recurrent_tid}/subscription"
# Perform the request
full_resp ? self.resp = self.put_request : self.resp = self.put_json_request
# return it received resp
self.resp
end
- # Stop a recurrence based on it transaction rid
- def unsubscribe(rid=nil, full_resp=false)
+ # Stop a recurrence based on it transaction tid
+ def unsubscribe(tid=nil, full_resp=false)
# SetUp
- self.recurrent_rid = rid if rid
- self.path = "transactions/#{self.recurrent_rid}/subscription/unsubscribe"
+ self.recurrent_tid = tid if tid
+ self.path = "transactions/#{self.recurrent_tid}/subscription/unsubscribe"
# Perform the request
full_resp ? self.resp = self.delete_request : self.resp = self.delete_json_request
# return it received resp
self.resp
end
# Return the payments executed for the purchase passed
- def payment_history(rid=nil, full_resp=false)
+ def payment_history(tid=nil, full_resp=false)
# SetUp
- self.recurrent_rid = rid if rid
- self.path = "transactions/#{self.recurrent_rid}/subscription/payment_history"
+ self.recurrent_tid = tid if tid
+ self.path = "transactions/#{self.recurrent_tid}/subscription/payment_history"
self.path = "#{self.path}#{self.request_params.it_keys_to_get_param}"
# Perform the request
full_resp ? self.resp = self.get_request : self.resp = self.get_json_request
# return it received resp
self.resp
end
# Check if a subscription is up-to-date or have any pending
- def up_to_date(rid=nil, full_resp=false)
+ def up_to_date(tid=nil, full_resp=false)
# SetUp
- self.recurrent_rid = rid if rid
+ self.recurrent_tid = tid if tid
# Create/customize the path & add the auth as param
- self.path = "transactions/#{self.recurrent_rid}/subscription/up-to-date"
+ self.path = "transactions/#{self.recurrent_tid}/subscription/up-to-date"
self.path = "#{self.path}#{self.request_params.it_keys_to_get_param}"
# Perform the request
full_resp ? self.resp = self.get_request : self.resp = self.get_json_request
# return it received resp
self.resp
end
+ # return it hash resp when resp is a string
+ def hash_resp
+ self.resp.is_a?(String) ? JSON.parse(self.resp).it_keys_to_sym : self.resp
+ end
+
# ================ STATIC methods ================
- # GET /api/transactions/:rid by the rid passed
- def self.find(rid)
+ # GET /api/transactions/:tid by the tid passed
+ def self.find(tid)
end
end
end
\ No newline at end of file