Ste_95
Ste_95

Reputation: 371

Generate paypal payment links with amout and recipient

I need to dinamically generate PayPal links with customized payment amounts and recipients. I don't know much about PayPal's way of handling this kind of stuff, and I actually wonder whether it is possible. I have a table with user's email address and payment value and, on the last column, I need to put that link that, clicked, takes to the PayPal's page where, after security checks and everything, the amount of money by me given can be directly transferred to the email address of the user.

Is it possible to do something like this? I'm working in PHP. Thanks.

Upvotes: 0

Views: 996

Answers (1)

jancha
jancha

Reputation: 4967

please, read documentation - it's all very well described. you will need to register at https://developer.paypal.com/; refer to https://www.paypal.com/documentation for more information.

I believe paypal standard payments would suffice your needs. read this https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_WebsitePaymentsStandard_IntegrationGuide.pdf -- it has all sorts of samples.


when we integrate paypal, we usually do like this: user picks goods to purchase, then proceeds to checkout. at this point, form is created as per documentation, and that form includes merchant account to use for processing the payment. in the form you also specify: notify_url and cancel_url, so you would get notification from the paypal as to what happened and to which account. that should address your needs.

sample form:

<form action="https://www.'.$this->isSandbox().'paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="'.$this->api->getConfig('billing/paypal/merchant').'">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="item_name" value="'.addslashes($_GET['descr']).'"> 
<input type="hidden" name="item_number" value="'.addslashes($_GET['id']).'"> 
<input type="hidden" name="amount" value="'.addslashes($_GET['amount']).'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="notify_url" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('ipn'=>$_GET['id'])).'">
<input type="hidden" name="cancel_return" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('cancel'=>$_GET['id'])).'">
<input type="hidden" name="return" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('success'=>$_GET['id'])).'">
<input type="hidden" name="currency_code" value="'.addslashes($_GET['currency']).'"> 
</form>

sample callback handler:

....

if($_POST){
    // might be getting adta from paypal! better log!
    foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";
    $postdata.="cmd=_notify-validate";
    $curl = curl_init("https://www.".$this->isSandbox()."paypal.com/cgi-bin/webscr");
    curl_setopt ($curl, CURLOPT_HEADER, 0);
    curl_setopt ($curl, CURLOPT_POST, 1);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
    $response = curl_exec ($curl);
    curl_close ($curl);
    $this->api->logger->logLine($response);
    if ($response != "VERIFIED"){
        $this->api->logger->logLine('FAILED: post='.print_r($_POST,true));
        exit;
    }else{
        $this->api->logger->logLine('VERIFIED: post='.print_r($_POST,true));
    }
    if($_POST['payment_status']=='Completed' and $_POST['txn_type']!='reversal')return true; // or perform your desired actions

    exit;
}

excerpt from agiletoolkit.org paypal billing addon

Upvotes: 2

Related Questions