Results 1 to 6 of 6

Thread: What's wrong with this code? (cURL post form)

  1. #1
    Join Date
    Nov 2009

    What's wrong with this code? (cURL post form)

    I'm trying to write a script to submit this html form.
    HTML Code:
    <!-- "Add to cart" button -->
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">  
    <!-- Identify your business so that you can collect the payments. -->  
    <input type="hidden" name="business" value="shadow_1265397352_biz@samerica.com">  
    <!-- Specify a PayPal Shopping Cart Add to Cart button. -->  
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="add" value="1">
    <!-- Specify details about the item that buyers will purchase. -->  
    <input type="hidden" name="item_name" value="widget">  
    <input type="hidden" name="amount" value="5.95">  
    <input type="hidden" name="currency_code" value="USD">
    <!-- Require a shipping address. --> 
    <input type="hidden" name="no_shipping" value="2">
    <!-- Set your "continue shopping" page --> 
    <input type="hidden" name="shopping_url" value="http://www.google.com/"> 
    <!-- Display the payment button. -->  
    <input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" alt="PayPal - The safer, easier way to pay online">  
    <img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >  
    This works ok, but when I try to do the same thing in php, the target doesn't seem to receive any data.
    PHP Code:
    ['business'] = 'shadow_1265397352_biz@samerica.com';
    $post_data['cmd'] = '_cart';
    $post_data['add'] = '1';

    $post_data['item_name'] = 'widget';
    $post_data['amount'] = '5.95';
    $post_data['currency_code'] = 'USD';

    $post_data['no_shipping'] = '2';

    //create cURL connection
    $curl_connection curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
    //set options
    curl_setopt($curl_connectionCURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    //set data to be posted
    //perform our request
    $result curl_exec($curl_connection);
    //close the connection

    What am I doing wrong? Thank you in advance for any help you can give.

  2. #2
    Join Date
    Nov 2009
    I just tried sending it to another page I wrote, and it received every field of data just fine. Could there be something odd about the paypal site that doesn't allow this?

    EDIT: Ok, I have a theory on what might be the problem, or at least part of it. Can anyone tell me how likely this is? Since paypal uses sessions to store the shopping cart, that has to be connected to an IP address, right? But when I submit the form, it uses the server's ip, not the user's. This means that when you view the cart after the script executes, it doesn't show anything.

    Actually, now that I write this, that can't be the reason this doesn't work. I've been running it off my hard drive, so my ip IS the server's ip. Also, the page it shows isn't what it should look like if it successfully added to the cart.

    Still, this will be a problem in the future, right? Is there any way I can avoid this, or am I just out of luck?
    Last edited by Topazan; 02-07-2010 at 02:09 AM.

  3. #3
    Join Date
    Jan 2009
    What is your end goal by avoiding the paypal interface? Users won't be able to complete the payment(s) if they are never given the payment page from paypal.

  4. #4
    Join Date
    Nov 2009
    I was trying to help a friend set up a website for her business. She though it would look unprofessional if the customers are directed to the paypal site every time they add something to their cart, so I was trying to set up a system that would store the cart on her site and send everything to paypal at once when the user is ready to checkout.

    After reading some more of the paypal documentation, it seems like the suggested procedure is combining all the purchases into one and sending that to paypal through a form. The problem I see with that is there would have to be a separate system in place for recording what was purchased.

    It's a moot point anyway, she decided to go with some pre-made online store software.

  5. #5
    Join Date
    Feb 2010
    Glasgow, UK
    I'd suggest you check with PayPal terms and conditions before doing that your doing. I understand that it's not the most professional look, but in the end PayPal might object to you avoiding the add-to-cart function.

    That said, I DO know you could create a site-side cart, using JavaScript for example, that can then be submitted in the one go to PayPal. Examples of that are on the PayPal site under their merchant tools.

  6. #6
    Join Date
    Jan 2009
    Usually when you are trying to create a more cohesive look-and-feel using paypal you use your own cart (server-side preferable) and pass the whole order to paypal when the user is ready to pay. Then you use the paypal IPN callback to mark the account paid once paypal has processed payment. By sending the data using Curl you were removing the user from the payment process which would in essence break your payment process since no payments would be made/received that way. It is the same technique used when you purchase payment gateway services such as authorize.net or others.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15884 seconds
  • Memory Usage 2,907KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates