Jump to content
Larry Ullman's Book Forums
DavidP

Shopping Cart For 1 Item, 1 Price And 1 Qty

Recommended Posts

I have two of Larry's books and and am considering buying this book if it can help me do what I need to do. I do not have a complicated e-commerce store with many products, sizes and quantities. I have one product, one price and it's sold one at a time. I have a job board where peopel can post one job ad for $95. If they want to post another job ad they start over.

 

I want to use PayPal's "PayPal Payments Advanced" as my payment processing. This cost $5 a month along with a transaction fee of 2.9% plus $.25-$.30. I'd like to use "PayPal Payments Advanced" because payments would be processed on my website instead of PayPal's standard payment system where the customer is taken to PayPal's site for payment processing.

 

To use "PayPal Payments Advanced" requires a shopping cart. I've looked at many but I do not need a hosted e-store website nor do I need a complicated system that I have to pay a $30-$50 a month subscription fee to. I also do not want to pay a one time fee of several hundred dollars for a shopping cart.

 

I already have my job ad database written and installed along with PayPal's IPN database. Employers post their job ad and then make payment. When PayPal sends the IPN report with a successfully completed payment, the jobs database is updated from "hide" job ad to "show" job ad. This works with my current system using PayPals "Buy Now" button and paying on PayPal's website. What I don't like about this is that their page is pre-set for people to pay with their PayPal account. The option to pay with a credit/debit card is below the pay with your PayPal account section and is easily missed. People are thrown off with the pay with your PayPal account because most do not have a PayPal account so they cancel the order. I don't want to overload my customers by posting detailed instructions on how to disregard the "Pay with your PayPal Account" section and find the "Pay with Credit/Debit Card" link.

 

Sorry for ALL that, but will this book help me to create a simple shopping cart that only has one product at one price and one quantity that will work with PayPal? I'm located in the U.S.

 

Thanks.

David

Share this post


Link to post
Share on other sites

I will let someone more knowledgeable answer your question about using this book.

I would suggest you look into using Stripe instead of PayPal or in addition to PayPal. I think it is much easier to implement.

You can check out the features and then decide

Share this post


Link to post
Share on other sites

I agree with abigail.

Given your situation, Stripe would be perfect for you, and the 2nd edition of the e-commerce book explains how to use Stripe in detail.

PayPal is quickly becoming a thing of the past. I say drop it and go with Stripe.

Share this post


Link to post
Share on other sites

Thanks for the support for the book and for Stripe, you two! 

 

If you're only selling one item at one price, you really shouldn't need a shopping cart. The book has a database-driven shopping cart, but that's well beyond your needs. I'd try Stripe or any service that will allow you to perform simple one-off charges.

Share this post


Link to post
Share on other sites

Thanks for the heads up about Stripe. I've never heaed of them but I'm on their page right now! Thanks again. Love the books Larry. I'll be getting this one soon!

Share this post


Link to post
Share on other sites

Hello,

 

I bought the book, but I'm struggling with Stripe. I have several questions, most of which I think can be easily answered.

 

I also read the tutorial at "http://www.larryullman.com/2012/10/10/introduction-to-stripe/" and I downloaded the codes associated with that tutorial -  buy.php, buy.js, etc.

 

In the book, the picture of the Stripe form shows inputs for the customer's first and last name, although in the form script I do not see these inputs. Same goes with the online tutorial that shows an input for the customer's email. So, I'm guessing that I have to include the email input into the form like below:

<label>Your Email:</label>
<input type="text" name="email" class="input-medium" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" />

Correct?

 

 

I'm currently using PayPal. I use a php IPN (fsockopen) script. PayPal collects all kinds of information from the customer via their payment form and sends that infomation to me in the form of php variables. The ones I'm most interested in are these:

$txn_id = escape_data($_POST['txn_id']);
$first_name = escape_data($_POST['first_name']);
$last_name = escape_data($_POST['last_name']);
$payer_email = escape_data($_POST['payer_email']);
$payment_date = escape_data($_POST['payment_date']);
$payment_status = escape_data($_POST['payment_status']);

I use the name and email to match the right customer in the database and the payment_status (if "Completed") to update the "display" column in the database to "2" to make the job ad viewable. Below is my jobs database setup:

CREATE TABLE IF NOT EXISTS `jobs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(25) NOT NULL DEFAULT '',
  `last_name` varchar(35) NOT NULL DEFAULT '',
  `email` varchar(155) NOT NULL DEFAULT '',
  `phone` varchar(25) NOT NULL DEFAULT '',
  `job_title` varchar(155) NOT NULL DEFAULT '',
  `company` varchar(155) NOT NULL DEFAULT '',
  `company_url` varchar(155) DEFAULT NULL,
  `address` varchar(155) DEFAULT NULL,
  `city` varchar(35) NOT NULL,
  `state` varchar(3) NOT NULL,
  `zip_code` varchar(10) DEFAULT NULL,
  `salary` varchar(255) DEFAULT NULL,
  `apply_email` varchar(85) DEFAULT NULL,
  `apply_website` varchar(155) DEFAULT NULL,
  `description` longtext NOT NULL,
  `display` tinyint(2) NOT NULL,
  `txn_id` varchar(30) NOT NULL,
  `payment_date` varchar(50) NOT NULL,
  `payment_status` varchar(15) NOT NULL,
  `submitted` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`id`)
);

Using:

MySQL Client API version - 5.1.73
PHP version - 5.2.17

 

In my Stripe account I checked to automatically send me and the customer confirmation of payment. Stripe has my email address, so will they just use the $email value the customer enters in the form to send a receipt to them?

 

 

I'm using the buy.php script in Larry's tutorial to process the payment information. To update the database after a successful payment I'm using this:

 // Check that it was paid:
if ($charge->paid == true)
{                
      // Store the order in the database.
      // Send the email.
      // Celebrate!

      $query = "SELECT COUNT(*) as num FROM jobs WHERE txn_id='' && email='$e'";
      $total_pages = mysql_fetch_array(mysql_query($query));
      $total_pages = $total_pages['num'];
      if ($total_pages >= 1)
      {
             $newdisplay = 1;
             $payment_status = "Completed";
             $txn_id = $id;

             $sqlupdate = "UPDATE jobs SET display='$newdisplay', txn_id='$txn_id', payment_gross='$payment_gross', payment_date = now(), payment_status='$payment_status' WHERE email='$e'";
             $result = mysql_query($sqlupdate);
       }
}

I'm looking at the picture (Figure 15.12) on page 511 of the book and see the Stripe Charge Object. I'm not sure which exactly is the order_id, but if it's the top id, I do not know how to change: [id] => ch_102jyI2BAZoCjj35RP3QgGkT into the $txn_id variable to update the database. In the above I have $txn_id = $id; but I am not sure that this is correct.

Share this post


Link to post
Share on other sites

I tested buy.php and it didn't work. No surprise there. Got the message:

 

 
Error!The following error(s) occurred:
  • The order cannot be processed. Please make sure you have JavaScript enabled and try again.

 

 

I have these javascript files in the header:

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript" src="js/buy.js"></script>

I also have this:

    // If no errors, process the order:
    if (empty($errors))
    {
        // create the charge on Stripe's servers - this will charge the user's card
        try {
            // Include the Stripe library:
            require_once('includes/stripe/lib/Stripe.php');

All are installed.

 

 

Share this post


Link to post
Share on other sites

David, you're kind of asking a lot of questions here. Can you be more specific about what help you need now? Also, re: PayPal, keep in mind the customer never leaves your site, so you can ask for and immediately receive any and all information you need from the customer. 

Share this post


Link to post
Share on other sites

Hi Larry,

 

Yes, sorry about that.

 

First, does my website need to be https:// in order to test Stripe?

 

I'm trying to use the buy.php script from your online tutorial.

 

I need to send Stripe the customer's email address so they can email them a receipt. I affirmed the "email customer a receipt" setting in Stripe. But I'm not 100% sure how to do that via the credit card form. I'm have this:

  • <input type="hidden" name="email" value="<?php {$_SESSION['eemail']} ?>">

    and this here:

    • // Charge the order:
      $charge = Stripe_Charge::create(array(
          "amount" => $amount, // amount in cents, again
          "currency" => "usd",
          "card" => $token,
          "email" => $e
          )
      );

      not sure if these are correct or not.

  • I also need to update my jobs database "txn_id" column with the Stripe order id #, but I'm not sure of the Stripe php variable for the order id #... UPDATE jobs SET txn_id='$order_id'

Thanks.

David

Share this post


Link to post
Share on other sites

Thanks for the clarifications. In answer to your questions...

 

No, you don't need SSL for testing purposes so long as you're not using real credit card numbers (which Stripe won't let you do anyway). 

 

As for the email address, if it's already stored in a session, you don't need to store it in a hidden form input. The use of $e in your PHP code would be correct if you've already assigned it a value previously. Also, the create charge call has no `email` parameter. It's `receipt_email`:

 

https://stripe.com/docs/api#create_charge

 

As for the transaction ID, if you store the result of the Stripe_Charge call to a variable (as in $charge), then $charge->id will have the Stripe-generated charge ID upon success:

 

https://stripe.com/docs/api#charges

Share this post


Link to post
Share on other sites

I purchased an SSL Certificate (just to get that out of the way) and Stripe is working in test mode. I still have a couple of questions but will get to those later.

Share this post


Link to post
Share on other sites

Hello again,

 

I'm back to working on my Stripe payment processing and while I'm beginning to understand it a little bit more I need to ask a couple of questions regarding the charge attributes. I need to take some information returned from Stripe and assign it a variable to be entered into a database table.

 

Specifically I need to know how to write a variable to get some of the charge card's child parameters. I write this to set a variable for the charge id:

$charge_id = $charge->id;

 

...so would I write a variable like below to get the card brand and funding...

 

$card_brand = $charge->$card->brand;

$card_type = $charge->$card->funding;

 

???

 

Thanks.

David

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...