lib/paypal_express/models/response.rb in killbill-paypal-express-5.0.6 vs lib/paypal_express/models/response.rb in killbill-paypal-express-5.0.7

- old
+ new

@@ -174,11 +174,11 @@ # Update the response row update!(updated_attributes) end - def transition_to_success(transaction_id, trx_plugin_info) + def transition_to_success(transaction_id, amount, currency) begin new_message = JSON.parse(message) original_message = nil rescue new_message = {} @@ -196,14 +196,20 @@ } # Update the response row update!(updated_attributes) + amount_in_cents = nil + unless amount.nil? + amount_in_cents = Monetize.from_numeric(amount.to_f, currency).cents.to_i + # Paypal search api returns a negative amount in case of successful refund + amount_in_cents = -amount_in_cents if amount_in_cents < 0 + end # Create the transaction row if needed (cannot have been created before or the state wouldn't have been UNDEFINED) build_paypal_express_transaction(:kb_account_id => kb_account_id, :kb_tenant_id => kb_tenant_id, - :amount_in_cents => trx_plugin_info.amount, - :currency => trx_plugin_info.currency, + :amount_in_cents => amount_in_cents, + :currency => currency, :api_call => api_call, :kb_payment_id => kb_payment_id, :kb_payment_transaction_id => kb_payment_transaction_id, :transaction_type => transaction_type, :payment_processor_account_id => payment_processor_account_id,