开发者

Setting Up a Simple Retreat Registration w/ PayPal API and PHP

开发者 https://www.devze.com 2023-01-14 01:40 出处:网络
So I\'m running out of time on this project and I posted here in hopes that someone can help me. Backstory

So I'm running out of time on this project and I posted here in hopes that someone can help me.

Backstory There's a church retreat coming up and I'm in charge of making the website.

The Meaty Info On the site there's a simple registration form on the page that has some basic information (I have to add fields for Location, Phone Number, and Address. Ignoring that...) Screenshot of the page here. Ignore the error at the top and the PayPal button, I was trying to get it to work but I'm doing something wrong.

Now the retreat site does checks in PHP when you submit the form to see that you put real information for all the fields. Hitting the submit button will call the register.php page and do the checks, returning whether or not there were any errors.

The Problem I've never used an API but I have a good knowledge of PHP. As of now, what I wanted to happen was:

  1. The user inputs their information on the church retreat site. The retreat site would then check if the information was correct, and if it was it would redirect them to a PayPal page very similair to this.
  2. There, they'd enter billing information, then, after completing and processing the order all on PayPal's site, PayPal would redirect to my church registration page.
  3. My site would (somehow) receive from PayPal that the transacti开发者_C百科on was successful, and then add the user to a database of paid attendees.

The problems are setting up PayPal on my site how I outlined. Then, how would my site know whether or not a transfer was successful? Where would I find the files necessary to do the API commands?

I have no idea how to do that. It's boggling my mind and after reading documentation, I've just become more confused. I need someone's help on this so if anyone cares to help me: Thank You. I could really use a human answer as to the steps I need to take to get this done.


To do what you're talking about, first you need to post a form to paypal. This pseudocode should help.

<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<input type='hidden' name='cmd' value='_cart' />
<input type='hidden' name='upload' value='1' />
<input type='hidden' name='business' value='{$paypal_email}' />
<input type='hidden' name='shopping_url' value='{$return_path}' />
<input type='hidden' name='currency_code' value='USD' />

(for each item in the cart, repeat...)

  <input type='hidden' name='item_number_{$one_based_counter}' value='{$item_number}'>
  <input type='hidden' name='item_name_{$one_based_counter}' value='{$item_name}'>
  <input type='hidden' name='amount_{$one_based_counter}' value='{$amount}'>
  <input type='hidden' name='quantity_{$one_based_counter}' value='{$quantity}'>

  (for each custom field for this item (e.g. size, style))

    <input type='hidden' name='on{$zero_based_counter}_{$one_based_counter}' 
                        value='{$custom_field_name[$zero_based_counter]}'>
    <input type='hidden' name='os{$zero_based_counter}_{$one_based_counter}' 
                        value='{$custom_field_value[$zero_based_counter]}'>

  (end for each)

(end for each)

<input type='submit' value='Pay Me' /></form>

After that, you need to write another script to handle payment notifications from PayPal. Look into PayPal's Instant Payment Notification (IPN). Log in to PayPal and have IPN post to your notification handler script. There are some pretty good IPN tutorials on PayPal's site and elsewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消