tags:

views:

52

answers:

1

I have two ways to check from user:

1.if user input (Amount field < 5(user credit):
   do update database the remain amount in my database table.
2.if user input(Amount field) > 5(user credit):
  Do paypal transaction with the submit form.



 <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">        
    <input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
    <input name="item_name" type="hidden" id="item_name"  size="45" value="Posting job">    
    <input type="hidden" name="cmd" value="_xclick">    
    <input type="hidden" name="no_note" value="1">    
    <input type="hidden" name="business" value="[email protected]">    
    <input type="hidden" name="currency_code" value="USD">    
    <input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/"&gt;       
    Paying Page:<input name="amount" type="text" id="amount" size="5">   
    <input type="submit" name="Submit" value="Pay">            
    </form>

Anybody could tell me how to do with the paypal submit form with the conditions.?

thanks.

Thanks @Donny Kurnia ,now I have tried:

EDIT::

function compare_user_credit($paying_price, $user_credit){

    $db = &JFactory::getDBO();
    $user =& JFactory::getUser();
    $user_id = $user->get('id');

    if ($paying_price <= $user_credit) {        
        $remain_credit = $user_credit - $paying_price;
        //DO UPDATE:enough credit
        update_user_credit_after_paying($remain_credit,$user_id);
        $action_after_paying = header("Location: index.php?xxxx=5");
     }
    # Case2 direct to paypal with the submit form.
    else if ($paying_price > $user_credit){
       //Need submit form to paypal.
       $action_after_paying = header("Location: index.php=xxxx&paypal=".$_POST["amount"]);
    }
    return $action_after_paying;
}
$output = '<form method="POST" > ';
     $output .='<h1>Credit:'.get_credit().'</h1>';
     $output .= ' Paying Page <input type="text" name="amount" size=3 max_length=5 />';
     $output .='<input type="submit" name="pay" value="pay" />' ;
     echo $output;

if(isset($_POST["pay"])){
    compare_user_credit($_POST["amount"], $user_credit);

}

HOw Could I do with Paypal in Case 02.(direct to paypal with submit form.)

+1  A: 

Maybe you can receive the form submit to your own code and then check it's value. If it satisfy the first condition, do the database update. If it satisfy the second condition, redirect the user to a page that have hidden form that will submit to paypal. You can populate the data in this hidden form using data from database or previous form input, and put a javascript code so the form will automatically submitted when the page is loaded.

In my code, I use Micah Carrick's Paypal IPN class to send data to paypal. The class have a sample code on how to display the hidden form, with a submit button in case the javascript is disabled.

Donny Kurnia
Thanks !Could give me suggestion How can I do in case 02 (check my updated posting)
python
okay .It works ,thank for your class.
python
Glad to hear it works, and btw, it's not my class, the credit should go to Micah ;) The class actually just wrap the code example that you can found in the Paypal developer's documentation, about IPN in PHP language. Micah did a great job put all these code into a class that can be easily used.
Donny Kurnia
I have a problem going to achieve .when you user click on button pay now I update my database(credit) too.with the script where could we modified,.
python
maybe you can asked that in the new question, and include the code or link to the live page. You can use paypal sandbox to test your code to make sure it's working as intended.
Donny Kurnia