conekta-ruby icon indicating copy to clipboard operation
conekta-ruby copied to clipboard

What does amount_refunded field means?

Open Senen opened this issue 5 years ago • 0 comments

Hi there, i am working on an implementation using your gem and i am testing refunds but i do not understand the meaning/behavior of the field amount_refunded.

Before to this refunds logs i created a new charge of 5000 MXN first. I used the latest 2.4.2 version.

2.6.3 :054 > order = Conekta::Order.find "ord_2nPKyqEbpdpNFQktQ"
 => {"livemode"=>false, "amount"=>5000, "currency"=>"MXN", "payment_status"=>"paid", "amount_refunded"=>0, "customer_info"=>{"email"=>"[email protected]", "name"=>"Jane Doe", "corporate"=>false, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "object"=>"customer_info"}, "object"=>"order", "id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{"reference"=>"cf568c12-a90c-41a9-bc7c-c4d04fad55a5"}, "created_at"=>1584738150, "updated_at"=>1584738150, "line_items"=>{0=>{"name"=>"A Test Payment", "unit_price"=>5000, "quantity"=>1, "object"=>"line_item", "id"=>"line_item_2nPKyqEbpdpNFQktN", "parent_id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{}, "antifraud_info"=>{}}}, "charges"=>{0=>{"id"=>"5e752f66431e7249b10eee0c", "livemode"=>false, "created_at"=>1584738150, "currency"=>"MXN", "payment_method"=>{"name"=>"Jane Doe", "exp_month"=>"10", "exp_year"=>"25", "auth_code"=>"882769", "object"=>"card_payment", "type"=>"credit", "last4"=>"5100", "brand"=>"mastercard", "issuer"=>"banorte", "account_type"=>"BANORTE", "country"=>"MX", "fraud_indicators"=>[]}, "object"=>"charge", "description"=>"Payment from order", "status"=>"paid", "amount"=>5000, "paid_at"=>1584738150, "fee"=>458, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "order_id"=>"ord_2nPKyqEbpdpNFQktQ"}}}

At this point we have a paid order of 5000MXN!


2.6.3 :055 > order.refund(reason: :requested_by_client, amount: "1000")
 => {"livemode"=>false, "amount"=>5000, "currency"=>"MXN", "payment_status"=>"partially_refunded", "amount_refunded"=>0, "customer_info"=>{"email"=>"[email protected]", "name"=>"Jane Doe", "corporate"=>false, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "object"=>"customer_info"}, "object"=>"order", "id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{"reference"=>"cf568c12-a90c-41a9-bc7c-c4d04fad55a5"}, "created_at"=>1584738150, "updated_at"=>1584738205, "line_items"=>{0=>{"name"=>"A Test Payment", "unit_price"=>5000, "quantity"=>1, "object"=>"line_item", "id"=>"line_item_2nPKyqEbpdpNFQktN", "parent_id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{}, "antifraud_info"=>{}}}, "charges"=>{0=>{"id"=>"5e752f66431e7249b10eee0c", "livemode"=>false, "created_at"=>1584738150, "currency"=>"MXN", "payment_method"=>{"name"=>"Jane Doe", "exp_month"=>"10", "exp_year"=>"25", "auth_code"=>"882769", "object"=>"card_payment", "type"=>"credit", "last4"=>"5100", "brand"=>"mastercard", "issuer"=>"banorte", "account_type"=>"BANORTE", "country"=>"MX", "fraud_indicators"=>[]}, "object"=>"charge", "description"=>"Payment from order", "status"=>"partially_refunded", "amount"=>5000, "paid_at"=>1584738150, "fee"=>458, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "order_id"=>"ord_2nPKyqEbpdpNFQktQ", "refunds"=>{0=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752f9d431e7256d50dd650", "created_at"=>1584738205}}}}}

At this point i refunded 1000 of 5000 MXN but amount_refunded is zero!

2.6.3 :056 > order = Conekta::Order.find "ord_2nPKyqEbpdpNFQktQ"
 => {"livemode"=>false, "amount"=>5000, "currency"=>"MXN", "payment_status"=>"partially_refunded", "amount_refunded"=>0, "customer_info"=>{"email"=>"[email protected]", "name"=>"Jane Doe", "corporate"=>false, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "object"=>"customer_info"}, "object"=>"order", "id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{"reference"=>"cf568c12-a90c-41a9-bc7c-c4d04fad55a5"}, "created_at"=>1584738150, "updated_at"=>1584738205, "line_items"=>{0=>{"name"=>"A Test Payment", "unit_price"=>5000, "quantity"=>1, "object"=>"line_item", "id"=>"line_item_2nPKyqEbpdpNFQktN", "parent_id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{}, "antifraud_info"=>{}}}, "charges"=>{0=>{"id"=>"5e752f66431e7249b10eee0c", "livemode"=>false, "created_at"=>1584738150, "currency"=>"MXN", "payment_method"=>{"name"=>"Jane Doe", "exp_month"=>"10", "exp_year"=>"25", "auth_code"=>"882769", "object"=>"card_payment", "type"=>"credit", "last4"=>"5100", "brand"=>"mastercard", "issuer"=>"banorte", "account_type"=>"BANORTE", "country"=>"MX", "fraud_indicators"=>[]}, "object"=>"charge", "description"=>"Payment from order", "status"=>"partially_refunded", "amount"=>5000, "paid_at"=>1584738150, "fee"=>458, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "order_id"=>"ord_2nPKyqEbpdpNFQktQ", "refunds"=>{0=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752f9d431e7256d50dd650", "created_at"=>1584738205}}}}} 

Here we did another refund of 1000 MXN but the order shows amount_refunded with 1000 MXN. At this point I already refunded 2000 of 5000 MXN. Do not understand why its returning amount_refunded=1000. 🤔

2.6.3 :057 > order.refund(reason: :requested_by_client, amount: "1000")
 => {"livemode"=>false, "amount"=>5000, "currency"=>"MXN", "payment_status"=>"partially_refunded", "amount_refunded"=>1000, "customer_info"=>{"email"=>"[email protected]", "name"=>"Jane Doe", "corporate"=>false, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "object"=>"customer_info"}, "object"=>"order", "id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{"reference"=>"cf568c12-a90c-41a9-bc7c-c4d04fad55a5"}, "created_at"=>1584738150, "updated_at"=>1584738230, "line_items"=>{0=>{"name"=>"A Test Payment", "unit_price"=>5000, "quantity"=>1, "object"=>"line_item", "id"=>"line_item_2nPKyqEbpdpNFQktN", "parent_id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{}, "antifraud_info"=>{}}}, "charges"=>{0=>{"id"=>"5e752f66431e7249b10eee0c", "livemode"=>false, "created_at"=>1584738150, "currency"=>"MXN", "payment_method"=>{"name"=>"Jane Doe", "exp_month"=>"10", "exp_year"=>"25", "auth_code"=>"882769", "object"=>"card_payment", "type"=>"credit", "last4"=>"5100", "brand"=>"mastercard", "issuer"=>"banorte", "account_type"=>"BANORTE", "country"=>"MX", "fraud_indicators"=>[]}, "object"=>"charge", "description"=>"Payment from order", "status"=>"partially_refunded", "amount"=>5000, "paid_at"=>1584738150, "fee"=>458, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "order_id"=>"ord_2nPKyqEbpdpNFQktQ", "refunds"=>{0=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752fb682c27237de8fa5c9", "created_at"=>1584738230}, 1=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752f9d431e7256d50dd650", "created_at"=>1584738205}}}}}

Re-fetching the order again to see if something has changed. But keeps the same!


2.6.3 :058 > order = Conekta::Order.find "ord_2nPKyqEbpdpNFQktQ"
 => {"livemode"=>false, "amount"=>5000, "currency"=>"MXN", "payment_status"=>"partially_refunded", "amount_refunded"=>1000, "customer_info"=>{"email"=>"[email protected]", "name"=>"Jane Doe", "corporate"=>false, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "object"=>"customer_info"}, "object"=>"order", "id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{"reference"=>"cf568c12-a90c-41a9-bc7c-c4d04fad55a5"}, "created_at"=>1584738150, "updated_at"=>1584738230, "line_items"=>{0=>{"name"=>"A Test Payment", "unit_price"=>5000, "quantity"=>1, "object"=>"line_item", "id"=>"line_item_2nPKyqEbpdpNFQktN", "parent_id"=>"ord_2nPKyqEbpdpNFQktQ", "metadata"=>{}, "antifraud_info"=>{}}}, "charges"=>{0=>{"id"=>"5e752f66431e7249b10eee0c", "livemode"=>false, "created_at"=>1584738150, "currency"=>"MXN", "payment_method"=>{"name"=>"Jane Doe", "exp_month"=>"10", "exp_year"=>"25", "auth_code"=>"882769", "object"=>"card_payment", "type"=>"credit", "last4"=>"5100", "brand"=>"mastercard", "issuer"=>"banorte", "account_type"=>"BANORTE", "country"=>"MX", "fraud_indicators"=>[]}, "object"=>"charge", "description"=>"Payment from order", "status"=>"partially_refunded", "amount"=>5000, "paid_at"=>1584738150, "fee"=>458, "customer_id"=>"cus_2nPGHDYf44CQYA4pj", "order_id"=>"ord_2nPKyqEbpdpNFQktQ", "refunds"=>{0=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752fb682c27237de8fa5c9", "created_at"=>1584738230}, 1=>{"object"=>"refund", "amount"=>-1000, "auth_code"=>"882769", "id"=>"5e752f9d431e7256d50dd650", "created_at"=>1584738205}}}}} 

Can you help me?

Thanks in advance!

Senen avatar Mar 23 '20 10:03 Senen