Skip to content

Commit 3ffa0e5

Browse files
committed
Merge pull request #6 from jupazave/backend
Se agrega modelo de pagos
2 parents 797ab65 + c9bbac2 commit 3ffa0e5

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

app/controllers/webhook_controller.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ def push
1616
elsif data_json['type'] == "charge.success"
1717

1818
PaymentNotification.compropago(data_json).deliver
19+
20+
Payment.create({
21+
service: true,
22+
product: data_json['data']['object']['product_name'],
23+
price: data_json['data']['object']['amount'].to_f,
24+
fee: data_json['data']['object']['fee'].to_f,
25+
name: data_json['data']['object']['payment_details']['customer_name'],
26+
email: data_json['data']['object']['payment_details']['customer_email']
27+
})
1928

2029
mensaje = "Se recibío un pago de $#{data_json['data']['object']['amount']}"
2130

@@ -52,6 +61,15 @@ def paypal
5261

5362
PaymentNotification.paypal(params).deliver
5463

64+
Payment.create({
65+
service: false,
66+
product: params[:item_name1],
67+
price: params[:mc_gross].to_f,
68+
fee: params[:mc_fee].to_f,
69+
name: "#{params[:first_name]} #{params[:last_name]}",
70+
email: params[:email]
71+
})
72+
5573
mensaje = "Se ha recibido un pago en paypal de $#{params[:mc_gross]} #{params[:mc_currency]}"
5674

5775
end

app/models/payment.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Payment < ActiveRecord::Base
2+
3+
def payment?
4+
if self.service
5+
return "compropago"
6+
end
7+
return "paypal"
8+
end
9+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreatePayments < ActiveRecord::Migration
2+
def change
3+
create_table :payments do |t|
4+
t.boolean :service
5+
t.string :product
6+
t.decimal :price, :precision => 8, :scale => 2
7+
t.decimal :fee, :precision => 8, :scale => 2
8+
t.string :name
9+
t.string :email
10+
11+
t.timestamps
12+
end
13+
end
14+
end

test/fixtures/payments.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
# This model initially had no columns defined. If you add columns to the
4+
# model remove the '{}' from the fixture names and add the columns immediately
5+
# below each fixture, per the syntax in the comments below
6+
#
7+
one: {}
8+
# column: value
9+
#
10+
two: {}
11+
# column: value

test/models/payment_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class PaymentTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)