dongtaihui5131 2010-09-03 02:23
浏览 27
已采纳

使用PayPal API和PHP设置简单的撤退注册

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 transaction 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.

  • 写回答

1条回答 默认 最新

  • doukaizha5417 2010-09-03 02:46
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效