Builds for
1 pipeline
failed
in
0 seconds
Merge branch 'specs' into 'master'
Specs Avances de specs antes de revisión y continuar See merge request !5
Showing
10 changed files
with
94 additions
and
9 deletions
lib/conekta_card_handler.rb
0 → 100644
lib/conekta_handler.rb
0 → 100644
1 | +module Var | ||
2 | + class ConektaHandler | ||
3 | + PAYMENT_METHOD_STRING = 'Conekta_payment'.freeze | ||
4 | + | ||
5 | + class << self | ||
6 | + def analyze(event) | ||
7 | + process_payment event[:data][:object] if | ||
8 | + event[:data][:object][:status] == "paid" | ||
9 | + process_charge event[:data][:object] | ||
10 | + end | ||
11 | + | ||
12 | + def process_payment(payment_info) | ||
13 | + object = Var.find_charge payment_info[:id] | ||
14 | + time = Time.strptime payment_info[:paid_at].to_s, '%s' | ||
15 | + amount = payment_info[:amount].to_f / 100.0 | ||
16 | + fee = payment_info[:fee].to_f / 100.0 | ||
17 | + | ||
18 | + object.update(var_fee: fee, var_paid_amount: amount, | ||
19 | + var_payment_method: self::PAYMENT_METHOD_STRING, | ||
20 | + var_payment_at: time, | ||
21 | + var_status: payment_info[:status]) | ||
22 | + end | ||
23 | + | ||
24 | + def process_charge(charge_info) | ||
25 | + # TODO: raise error if object is nil | ||
26 | + object = Var.find_charge charge_info[:id] | ||
27 | + object.update(var_status: charge_info[:status]) | ||
28 | + end | ||
29 | + end | ||
30 | + end | ||
31 | +end | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
lib/conekta_oxxo_handler.rb
0 → 100644
lib/conekta_payout_handler.rb
0 → 100644
lib/conekta_spei_handler.rb
0 → 100644
1 | class AddVarStatusTo<%=@model_name.pluralize.camelize%> < ActiveRecord::Migration | 1 | class AddVarStatusTo<%=@model_name.pluralize.camelize%> < ActiveRecord::Migration |
2 | def change | 2 | def change |
3 | - add_column :<%=@model_name.pluralize.underscore%>, :var_status, :string, default: 'pending' | 3 | + add_column :<%=@model_name.pluralize.underscore%>, :var_status, :string, default: 'pending_payment' |
4 | add_column :<%=@model_name.pluralize.underscore%>, :var_barcode_url, :string | 4 | add_column :<%=@model_name.pluralize.underscore%>, :var_barcode_url, :string |
5 | add_column :<%=@model_name.pluralize.underscore%>, :var_barcode, :string | 5 | add_column :<%=@model_name.pluralize.underscore%>, :var_barcode, :string |
6 | add_column :<%=@model_name.pluralize.underscore%>, :var_payment, :datetime | 6 | add_column :<%=@model_name.pluralize.underscore%>, :var_payment, :datetime | ... | ... |
... | @@ -2,6 +2,11 @@ require 'var/version' | ... | @@ -2,6 +2,11 @@ require 'var/version' |
2 | require 'conekta' | 2 | require 'conekta' |
3 | require 'paypal-sdk-rest' | 3 | require 'paypal-sdk-rest' |
4 | require 'acts_as_chargeable' | 4 | require 'acts_as_chargeable' |
5 | +require 'conekta_handler' | ||
6 | +require 'conekta_oxxo_handler' | ||
7 | +require 'conekta_card_handler' | ||
8 | +require 'conekta_spei_handler' | ||
9 | +require 'conekta_payout_handler' | ||
5 | 10 | ||
6 | # Main Module | 11 | # Main Module |
7 | module Var | 12 | module Var |
... | @@ -25,19 +30,29 @@ module Var | ... | @@ -25,19 +30,29 @@ module Var |
25 | 30 | ||
26 | def conekta_webhook(event) | 31 | def conekta_webhook(event) |
27 | raise "Hash expected, received #{event.class}" unless event.class == Hash | 32 | raise "Hash expected, received #{event.class}" unless event.class == Hash |
28 | - raise 'Malformed hash received' unless event[:data] && | 33 | + raise 'Malformed hash received' unless (event[:data] && |
29 | - event[:data][:object] | 34 | + event[:data][:object]) || |
30 | - payment = event[:data][:object] | 35 | + event[:object] |
31 | - process_charge_creation_with_card event | 36 | + if event.keys[0] == :object |
37 | + ConektaPayoutHandler.analyze(event) | ||
38 | + else | ||
39 | + payment_type = event[:data][:object][:payment_method][:object] | ||
40 | + case payment_type | ||
41 | + when "cash_payment" | ||
42 | + ConektaOxxoHandler.analyze(event) | ||
43 | + when "card_payment" | ||
44 | + ConektaCardHandler.analyze(event) | ||
45 | + when "bank_transfer_payment" | ||
46 | + ConektaSpeiHandler.analyze(event) | ||
47 | + end | ||
48 | + end | ||
49 | + # payment = event[:data][:object] | ||
32 | # object = Var.find_charge payment[:id] | 50 | # object = Var.find_charge payment[:id] |
33 | # # object.handle_conekta_event | 51 | # # object.handle_conekta_event |
34 | # update_object_var_data(object, payment) | 52 | # update_object_var_data(object, payment) |
35 | # object | 53 | # object |
36 | end | 54 | end |
37 | 55 | ||
38 | - def process_charge_creation_with_card(p) | ||
39 | - end | ||
40 | - | ||
41 | def update_object_var_data(object, data) | 56 | def update_object_var_data(object, data) |
42 | payment = data | 57 | payment = data |
43 | object.update_columns(var_status: payment[:status]) | 58 | object.update_columns(var_status: payment[:status]) |
... | @@ -51,7 +66,7 @@ module Var | ... | @@ -51,7 +66,7 @@ module Var |
51 | end | 66 | end |
52 | 67 | ||
53 | def find_charge(id) | 68 | def find_charge(id) |
54 | - Rails.application.eager_load! if Rails.env.development? | 69 | + # Rails.application.eager_load! if Rails.env.development? |
55 | @@var_classes.map do |class_name| | 70 | @@var_classes.map do |class_name| |
56 | class_name.where(var_id: id) | 71 | class_name.where(var_id: id) |
57 | end.flatten.first | 72 | end.flatten.first | ... | ... |
spec/conekta_handler_spec.rb
0 → 100644
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe ConektaHandler do | ||
4 | + it 'processes oxxo payment' do | ||
5 | + end | ||
6 | + | ||
7 | + it 'processes card payment' do | ||
8 | + end | ||
9 | + | ||
10 | + it 'processes oxxo payment' do | ||
11 | + end | ||
12 | + | ||
13 | + it 'processes payout' do | ||
14 | + end | ||
15 | +end | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment