Reputation: 2953
I am working on a marketplace app for hotel bookings. The model flow goes like this
Host has_many
Hotels
Hotel has_many
Rooms
Room & Guest has_many
Bookings
The Booking
model has fields with :room_id, :total_price, guest_id etc
Now comes the payment
part.. Where should I keep the payment gateway responses like payment_status
, pg_error_message
? Is it good practice to keep those in booking model itself? Or should I create a new model for sale?
like... Booking has_one
Sale
Is there a preferred approach here??
Upvotes: 0
Views: 96
Reputation: 384
I think you'll need another model, because you can have more than one reponse like and more than one transaction.
3rd Cancelled, 2017-01-15
2nd Captured, 2016-12-01
1st Aprroved, 2016-12-01
So, if you have another relation you can register a more consistent responses, i don't know what information gateways will return in your country, but in Brazil we store something like this, i will show the models of my application!
Invoice
price: float # Total price of invoice
paid:bool # If is paid, i can have a method insted of store this in DB
uuid: string # Some gateways need this
...
InvoicePayment
payment_method: int # Payment Metod selected from user.
gateway: string # Who process my payment.
fees: float # Fees charged in this transaction
transaction_token:string # ID and Token and whatever i need to >>>
transaction_id:string # identify the transaction on the gateway
transaction_key:string
auth_code: string
captured:bool # I already captured this transaction?
af_status: string # Anti Fraud response data
af_score: string
value: float # value of transaction, imagine that i can receive a invoice in more than one transaction.
That's all, i'm sure that i have some particularities in my country, but i think that is a main idea.
Sya!
Upvotes: 1