Private messaging between buyer and seller after purchase and before stripe transfer

After integrating Stripe (thank you again), I want the buyer and seller to communicate with each other through a messenger like mailboxer (https://github.com/mailboxer/mailboxer) before the buyer marks the purchase as complete and the seller confirms it which completes the transaction and transfers the money (like Fiverr). How would you do this?

Posted over 4 years ago by Omar Amiri
Posted over 4 years ago by Alex Yang

I think I understand. You'll need to add an extra step to the ordering process - instead of having the transaction go through immediately, the process would look like this:

1) Buyer makes the purchase, but the money is held in escrow.
2) Buyer and Seller communicate as needed.
3) Seller confirms that the transaction is complete, which releases the payment from escrow and it gets transferred to the Seller.

Is that right?

The main difference is that you'll need to add a boolean (true/false) field (let's call it 'confirmation') to your Orders database. When Buyers place an order, 'confirmation' should be set to false by default and the payment should be collected via Stripe. You'll then need to add a new action to your Orders controller to give Sellers the ability to toggle this to true. Once they do that, the Stripe transfer should be initiated.

I haven't used mailboxer before, but the above should outline what the Buyer-Seller transaction process should look like. Hope that helps!

1
Posted over 4 years ago by Omar Amiri

Yes, mostly!

In step 3 the seller confirms the transaction complete and then the buyer gets a notification to mark the transaction as complete, which then releases the payment from escrow. (If seller doesn't mark complete after 5 business days then money will be released as well)

Until I asked you, I thought I needed to create another scaffold for conversations to do this but I guess that would be wrong. I have absolutely no idea on how to add those steps in to the Orders database.

Could you help?

Thanks

1
Posted over 4 years ago by Alex Yang

Try to break the problem down into its smallest components. It's usually much easier to tackle a new feature by using an incremental approach. Adding a 'confirmation' field to your Orders database is pretty similar to the approach you use to add any new field to a database - you need to generate and run a migration. There's a good example of how to do this in the 'Add User Fields' video in the Yelpdemo course. Here's the link: https://baserails.com/courses/yelpdemo/add-user-fields

1
Posted over 4 years ago by Omar Amiri

I love how you said "break the problem down into its smallest components". I followed your advice and added the confirmations field and set it equal to false. Then in my orders controller I added an if statement before the transfer as such:

if @order.confirmation == true
transfer = Stripe::Transfer.create(
:amount => (@profile.price * 90).floor,
:currency => "usd",
:destination => @seller.recipient
)
end

This code allows the card to successfully be charged. Then I went into my rails console and set it equal to 'true' thinking it will begin the transfer. For some reason nothing happened.

Do you have any idea why?

1
Posted over 4 years ago by Alex Yang

The code that you wrote will only be run when that controller-action is triggered. In other words, your app won't constantly listen for when 'confirmation' becomes true and then run the code immediately. So don't try to manually trigger the code via the Rails console - instead, try placing an order through your app and see if it works.

1
Posted over 4 years ago by Omar Amiri

Before adding the if statement, I placed orders through the app to make sure it was working fine. When a user makes a purchase, it automatically creates a transfer to the seller. Now it's just adding logic into the code to only transfer money to sellers once the sellers selects the "complete service for buyer" button

1
Posted over 4 years ago by Alex Yang

The "complete service for buyer" button needs to link to a new action in your controller. Since you only want to transfer the money once the Seller clicks this button, your transfer code then belongs in this new action, not in your original 'create' action.

1