Created
December 1, 2015 19:38
-
-
Save nelyj/977e9d8bc7a2d179eaa7 to your computer and use it in GitHub Desktop.
Modelo de booking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 require_relative './concerns/bookable' | |
2 | |
3 class Booking < ActiveRecord::Base | |
4 include Bookable | |
5 | |
6 belongs_to :profile | |
7 belongs_to :service | |
8 | |
9 def payment!(current_user) | |
10 amount = 1 | |
11 client = Khipu::PaymentsApi.new | |
12 profile_service = self.service.profile_services.where(profile_id: current_user.profile.id).first | |
13 amount = profile_service.price.to_i if profile_service.price.to_i > 0 #la cantidad no puede ser 0 porque da error | |
14 binding.pry | |
15 response = client.payments_post("Kiipet - Pagar resevar", 'CLP', amount, { | |
16 transaction_id: self.id, #en mi caso pongo el id nomas | |
17 expires_date: DateTime.new(2016, 4, 4), | |
18 body: 'Estas pagando el precio del servicio que solicitaste para tu mascota', | |
19 picture_url: 'http://beta.kiipet.com/assets/logo-b3c6c14f85440776f61ce91dd045557e.png', | |
20 return_url: 'http://localhost:3000/payments/thanks', #url de exito | |
21 cancel_url: 'http://localhost:3000/payments/cancel', #url de fracaso | |
22 #notify_url: 'http://mi-ecomerce.com/backend/notify', | |
23 notify_api_version: '1.3' #version de api | |
24 }) | |
25 self.payment_id = response.payment_id if response #guadar id de la respuesta para preguntar el estado | |
26 self.save | |
27 | |
28 return response | |
29 end | |
30 end | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment