Ricardo Garcia

Redesigns webhook managment

......@@ -28,10 +28,14 @@ module Var
raise 'Malformed hash received' unless event[:data] &&
event[:data][:object]
payment = event[:data][:object]
object = Var.find_charge payment[:id]
# object.handle_conekta_event
update_object_var_data(object, payment)
object
process_charge_creation_with_card event
# object = Var.find_charge payment[:id]
# # object.handle_conekta_event
# update_object_var_data(object, payment)
# object
end
def process_charge_creation_with_card(p)
end
def update_object_var_data(object, data)
......
......@@ -68,17 +68,23 @@ describe Var do
it 'handles Cargo creado con tarjeta' do
params = {"data":{"object":{"id":"5511d4ce2412294cf6000081","livemode":false,"created_at":1427231950,"status":"pending_payment","currency":"MXN","description":"Stogies","reference_id":"9839-wolf_pack","failure_code":nil,"failure_message":nil,"monthly_installments":nil,"object":"charge","amount":20000,"paid_at":nil,"fee":963,"customer_id":"","refunds":[],"payment_method":{"name":"Jorge Lopez","exp_month":"12","exp_year":"19","auth_code":nil,"object":"card_payment","last4":"4242","brand":"visa"},"details":{"name":nil,"phone":nil,"email":nil,"line_items":[]}},"previous_attributes":{}},"livemode":false,"webhook_status":"pending","id":"5511d4ce2412294cf6000084","object":"event","type":"charge.created","created_at":1427231950,"webhook_logs":[{"id":"webhl_nPzGMBeQmMUu7aQ","url":"http://requestb.in/1em0jsx1","failed_attempts":0,"last_http_response_status":-1,"object":"webhook_log","last_attempted_at":0}]}
allow(Var).to receive(:find_charge).and_return chargable_product
allow(chargable_product).to receive(:update_columns).and_return true
allow(chargable_product).to receive(:var_payed?).and_return false
allow(chargable_product).to receive(:var_id).and_return '5511d4ce2412294cf6000081'
expect(Var).to receive(:process_charge_creation_with_card).with(params)
r = Var.conekta_webhook params
expect(r).to be true
end
xit 'processes card payment' do
result = Var.conekta_webhook params
expect(result.var_id).to eq('5511d4ce2412294cf6000081')
# allow(Var).to receive(:find_charge).and_return chargable_product
#
# allow(chargable_product).to receive(:update_columns).and_return true
# allow(chargable_product).to receive(:var_payed?).and_return false
# allow(chargable_product).to receive(:var_id).and_return '5511d4ce2412294cf6000081'
# expect(result.var_id).to eq('5511d4ce2412294cf6000081')
# TODO: Define what is actually being teted
pending
end
it 'handles Cargo pagado con tarjeta' do
......