Pulled info from webhook such as amount_paid, paid_at, payment_fee and payment_method
Showing
2 changed files
with
14 additions
and
2 deletions
| ... | @@ -7,5 +7,9 @@ class AddVarStatusTo<%=@model_name.pluralize.camelize%> < ActiveRecord::Migratio | ... | @@ -7,5 +7,9 @@ class AddVarStatusTo<%=@model_name.pluralize.camelize%> < ActiveRecord::Migratio |
| 7 | add_column :<%=@model_name.pluralize.underscore%>, :var_payment_expires_at, :datetime | 7 | add_column :<%=@model_name.pluralize.underscore%>, :var_payment_expires_at, :datetime |
| 8 | add_column :<%=@model_name.pluralize.underscore%>, :var_id, :string | 8 | add_column :<%=@model_name.pluralize.underscore%>, :var_id, :string |
| 9 | add_column :<%=@model_name.pluralize.underscore%>, :var_service, :string | 9 | add_column :<%=@model_name.pluralize.underscore%>, :var_service, :string |
| 10 | + add_column :<%=model_name.pluralize.underscore%>, :var_fee, :float | ||
| 11 | + add_column :<%=model_name.pluralize.underscore%>, :var_paid_amount, :float | ||
| 12 | + add_column :<%=model_name.pluralize.underscore%>, :var_payment_at, :datetime | ||
| 13 | + add_column :<%=model_name.pluralize.underscore%>, :var_payment_method, :string | ||
| 10 | end | 14 | end |
| 11 | end | 15 | end |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -30,8 +30,16 @@ module Var | ... | @@ -30,8 +30,16 @@ module Var |
| 30 | def self.conekta_webhook(params) | 30 | def self.conekta_webhook(params) |
| 31 | payment = params[:data][:object] | 31 | payment = params[:data][:object] |
| 32 | object = Var.find_charge payment[:id] | 32 | object = Var.find_charge payment[:id] |
| 33 | - object.update_columns(var_status: payment[:status]) | 33 | + case payment[:payment_method][:object] |
| 34 | - object.update_columns(var_payment_at: Time.zone.now) if object.var_payed? | 34 | + when "bank_transfer_payment" |
| 35 | + object.update_columns(var_payment_method: "Transferencia bancaria") | ||
| 36 | + when "cash_payment" | ||
| 37 | + object.update_columns(var_payment_method: "Pago en OXXO") | ||
| 38 | + when "card_payment" | ||
| 39 | + object.update_columns(var_payment_method: "Pago con tarjeta de crédito") | ||
| 40 | + end | ||
| 41 | + object.update({var_status: payment[:status], var_fee: payment[:fee], var_paid_amount: payment[:amount]) | ||
| 42 | + object.update_columns(var_payment_at: payment[:paid_at]) if object.var_payed? | ||
| 35 | object | 43 | object |
| 36 | rescue Exception => exception | 44 | rescue Exception => exception |
| 37 | false | 45 | false | ... | ... |
-
Please register or login to post a comment