Implementation Example #1

In the example we are using a custom brewed e-commerce system built from scratch.  Item data is retrieved from the database and stored in a session to be displayed on the item page.

 

 

  1.  We can simply enter this snippet of code snippet right on the checkout page before the final payment page.  In this example let’s say we insert this into a file called order-product-step-2.php.  This will create a basic unstyled form onto a page with an Apply button posting to a file in a directory called /codeBookie/coupon_verify.php

 

2.  When the visitor types in the coupon code into the text box and hits apply, it will make a post call the coupon_verify.php file

Here is an example source of coupon_verify.php

3.  Once this script has been called it will automatically redirect back to order-product-step-2.php.  The file should contain a conditional statement to display the coupon information.  We’ve done it like so beneath the rest of the order information on this particular website:

4.  For this website we are using Paypal’s ExpressCheckout API to complete the payment.  We need to send the codebookie checkout_token, coupon code and discount amount to Paypal to generate a token for checkout.

In our implementation we created a new condition to check if the codebookie session exists.

5.  The codeBookieNVP variable can then get appended to the rest of the NVP values to be sent off to Paypal for payment.   Please notice that we have $codeBookie_checkoutToken in the &PAYMENTREQUEST_0_CUSTOM so we can grab the checkout token later on when we post back to the IPN file.

6.  Once the buyer has entered the payment information into Paypal, we have Paypal have the information send all the payment details back to our IPN file.  The IPN file needs to be modified to check for the coupon details and information.

 

7.  If all the other logic checks out in the ipn file, such the transaction ID verification and it’s not a duplicate order then you can confirm the codebookie order to close this coupon and finalize it.

 

 

 

Was this article helpful to you? Yes No

How can we help?