OpenCart: Generate QR Code After Purchase - php

I would like to generate a qr code after the customer has successfully purchased the product. I am selling tickets to music events, so the idea is that when the customer purchases the ticket, I will generate a QR code and save that QR code in the database. Our mobile app will then run the code and check if it exists in the database.
How can I generate the QR code specifically after confirmation of a purchase?

In opencart, an order is saved in database even before it is confirmed by the customer (They are called as missing orders in case the order is never confirmed). You can see in catalog/controller/checkout/confirm.php
$this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data);
This is even before the purchase has been made. So you cannot add your module in add order.
You can call your method in checkout/success.php controller. But you have to be sure that your payment method redirects to success or the user clicks on the return link after he/she completes the payment.
Another way is that you call your method before/after the function for sending new order email is called after the customer confirms the order.

Related

Paypal login session then saves it for faster checkout

Well, I was wondering if it is possible to automatically logins the user in paypal everytime they checks out?
Given the scenario a new user registers in my site.
New User->Logins to paypal->get permissions(etc..)->approve->gets back to my site
So, everytime the user checks-out it automatically logins in paypal.
I would like to link his paypal account to his profile in my site thus easier check out
I saw the documents but it is just too much for me to comprehend.
It sounds like you are referring to reference transactions. With PayPal you can create a billing agreement, and you would save the billing agreement ID to the local user record in your database.
In the future when they are logged in and checking out on your site you can pull the billing agreement ID and pass that into a reference transaction request to PayPal. This will immediately process the new payment without any approval necessary, so you can simply display the order complete page to the user.
Their experience would be choosing their saved payment method, clicking to buy, and the complete page would show up immediately. No checkout forms or login (other than logging in to your site) necessary.
Depending on whether you're working with the Classic API or REST the specific calls would be different, but "reference transactions" and "billing agreements" are the terms you're looking for.

php paypal integration IPN

I'm trying to understand for a couple of days how is working the PayPal payment through IPN and all this things but I think my PHP level is not that high.
I am just trying to make a script like this.
Registered user on my website wants to download some content wich is allowed only for VIP User group and I need to add the BUY VIP function so… I set up sandbox, created Buy now button added to my website, created success and cancel page, created http://mysite/ipn.php page to recieve notifications the thing is that I'm not sure what should I write in ipn.php for execute next function after purchase:
UPDATE users set user_group='VIP' where id='$buyerid'

php - prevent using the same coupon code twice in paypal payment

The scenario is pretty simple.
In an e-commerce site, a certain user is given a coupon code and he can use it only once. Coupons are stored in database against each user's id.
Suppose the user adds a few products in the cart to make an order and enters the coupon and then clicks on the 'Pay Now' button and is redirected to the Paypal site for payment.
But the user uses a trick and does not pay just at that moment for the order he has just made. Instead he goes on to make another order by adding few other products in his cart and then again uses the single-time coupon and clicks the payment button to go to the Paypal site.
Now he makes payment for both the orders one after another and thus becomes successful to reuse the single-time coupon.
How to prevent the user from reusing the single-time coupon ? Should it take place before he is taken to the Pyapal site or after he is taken there ? and how above all?
I assume your coupon codes have two states, "used" and "unused" ..add a third state, "pending." When the user puts the coupon code in, validate it then mark it as pending. Once payment is confirmed mark it as "used" and don't let the user enter it again. If the user cancels their order you can make the coupon code "unused" again.
In case coupon is handled by you,
you can create single table, 2 columns:
coupon_id <-- primary key
order_id <-- probably you want this to be unique.
then you store coupon there, or if coupon is already there, you are checking if it is for same order_id.
Is this helping? Please comment and I will improve the answer.

Integrating Card Payments with Codeigniter

I've built a web application and I am looking to integrate cardsave's direct payment API into the application. I was wondering if anyone had any advise on the best way to do this.
Cardsave provide standard code for integrating: Download Gateway Integration Pack ZIP file
When a payment is made I need to store the CrossPaymentsReference and payment amount in my database, the rest I will leave to cardsave's api I have thought of a couple of solutions which should potentially work:
1) Using Views for all of the code and on sucessful payment and use Ajax to update the database with the crossPaymentReference and payment amount on sucessfull completion, because it involves minimal editing of the code, but does have a minor security risk because it sends the reference at the client end.
2) Create a library with the payment system class, put the preprocess payments and process payment code into a controller and copy the form into a view, and just a have a small model to update the database on sucessfull payment's. (I'm guessing this is the best way.)
3) Edit everything and build an MVC version of the code
My latest project runs on CI 2.0. I’ve integrated a payment system such as Card Save with success (in my case I use Ogone, which is a Belgian company).
Below I’ve detailed a bit how I implemented the order and payment system.
The advice I can give you is the following.
Keep your products, orders and payments in separate tables.
Link products to orders via a reference table (don’t store e.g. a list of product ID’s in a field in the order)
Allow that a payment can only have one order, but an order can have multiple payments (but only one paid). This way when a payment fails (e.g. the user pressed cancel on Card Saves payment page), you can just create a new payment on your side and let the user retry (unless Card Save accepts that you do 2 payment request with the same payment ID).
Make a separate library (not controller) that handles successfully paid orders. This library would e.g. activate a subscription that the user bought, or make a work order for someone to ship the products. By keeping it in a separate library you can extend its functionality (e.g. if for a specific product you would need to do something new) without touching at your payment logic (thus preventing heavy retesting).
Generate hashes when posting data, or redirecting users to checkout pages, pages that prepare the payment and recalculate the hashes each time to prevent that someone tampered with the data you posted or that is in the URL.
Make sure everything works without AJAX and add AJAX afterwards.
Basically the ordering process I came up with is divided as follows:
User adds services (I don’t sell physical products) to basket (using a modified version of CI’s shopping cart)
When done user clicks “Order products” which does a POST to the controller Place_order. The controller Place_order does the following things:
Check if the user is still logged in (in my case everyone needs to register before)
Get the products that are in the shopping cart and checks if they actually exist in the database (you never know)
Create a new order in the database and add the products to the order in the DB
Place_order doesn’t output anything, but redirects the user on success to a controller Checkout. Here I don’t use POST. This way you can reuse the URL (e.g. if the user decides to stop, he can continue the payment later). The URL contains the order ID and a hash.
The Checkout controller does the following
Recalculate the hash to see if no one tampered with the URL
Check if the order exists and isn’t paid yet
Check if the order belongs to the user logged in
Create the payment if it doesn’t exist yet
Show a view with a button “Cancel order” and “Pay order”. This is actually a form that contains in a hidden field the payment ID and a hash of the payment ID.
When clicking “Pay order”, a POST is done to a controller Pay_order. I don’t use GET, because I want that users only come on this page by posting data that was set by the Checkout controller. If they use GET to come on the page an error is thrown. This controller does the following:
Recalculate the hash to see of no one tampered with the posted data
Check if the payment exists and is not yet paid
If all is OK, compose the view that contains the necessary info to be posted to the payment service
Show the view.
When the user presses “Go to payment service” all data is posted to Ogone where the user executes the payment
When the payment is completed (correct or not) Ogone redirects the user back to me to a controller Payment_successfull or Payment_other (for errors etc). In the Payment_succesfull I call a library Purchase_activator which takes the payment ID as input. This one looks up the order and activates the services the user just paid. In the other case (on error) the user is shown a view with the correct error message and an option to retry or cancel.

What is common practice for handling backend data on eCommerce Confirm Order Page?

I'm seeking some guidance from people with experience in building ecommerce sites. This is actually my first time integrating with a payment gateway.
My implementation is actually a very basic booking system, where user places selects a date and number of tickets to book, clicks checkout and comes to a order confirmation screen, and then upon clicking submit again, user is brought to 3rd party payment gateway.
The 3rd party payment gateway url expects a post submission, containing a few mandatory fields for their api, one of which is a orderID to identify the order.
This is what I'm doing:
Unique order is generated when the ticket booking page is loaded.
User chooses what date he want, # of tickets, and clicks submit.
Data is validated, and then saved to a bookings table in db, while the user is brought to the confirmation page, presenting him/her with the details they have chosen and the price.
User clicks checkout, and the form is submitted to the 3rd party payment gateway url, user is brought to their page as well to complete payment.
Payment is completed, user is brought to our success page, payment gateway also posts details of transaction to a url of our choice which captures the transaction details, and saves it into a orders database.
So is that feasible ? My questions are:
Should unique order ID be generated as soon as ticket booking page is loaded ?
Should I have a booking database that saves bookings on the confirmation page ? What is user never clicks submit, then i'd eventually have a long list of records.. of course we could create some functionality to clean up the table, but is this common practice ?
Should I have a temporary booking database as mentioned above, as well as a completed transaction database that only captures transaction details from the payment gateway ? (Regardless of successful/failed)
Q1. Should unique order ID be generated as soon as ticket booking page is loaded ?
Ans: No, you should not do it at the time of load. Rather, should do it when the final submit is made for the 3rd Party payment gateway.
Q2. Should I have a booking database that saves bookings on the confirmation page ? What is user never clicks submit, then i'd eventually have a long list of records.. of course we could create some functionality to clean up the table, but is this common practice ?
Ans: Submit the form to your php script and make entry in the database only after submit is clicked. Then you can submit the form to the 3rd party from your php script once the enty has been made into your database.
Q3. Should I have a temporary booking database as mentioned above, as well as a completed transaction database that only captures transaction details from the payment gateway ? (Regardless of successful/failed)
Ans: Not required if followed what mentioned in answer for q2 above.
Hope this helps.

Categories