本文整理汇总了PHP中PayPal\Api\Transaction::setNotifyUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::setNotifyUrl方法的具体用法?PHP Transaction::setNotifyUrl怎么用?PHP Transaction::setNotifyUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Transaction
的用法示例。
在下文中一共展示了Transaction::setNotifyUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: payThroughPayPal
/**
* Создаем платеж типа paypal
* в случае успеха возвращает массив с ид-платежа,
* токеном и редирект-урлом куда нужно направить пользователя для оплаты
*
* @param double $pay_sum
* @param string $paymentInfo
* @param string $sku - internal UNIT ID
*
* @return array | null
*/
public function payThroughPayPal($pay_sum, $paymentInfo, $sku = null)
{
set_time_limit(120);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal($pay_sum);
$item1 = new Item();
$item1->setName($paymentInfo)->setCurrency('USD')->setQuantity(1)->setPrice($pay_sum);
// Ид товара/услуги на вашей стороне
if ($sku) {
$item1->setSku($sku);
}
$itemList = new ItemList();
$itemList->setItems([$item1]);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('Payment to DirectLink');
$transaction->setItemList($itemList);
$transaction->setNotifyUrl($this->config['url.notify_url']);
//**
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl($this->config['url.return_url']);
$redirect_urls->setCancelUrl($this->config['url.cancel_url']);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions([$transaction]);
$payment->setRedirectUrls($redirect_urls);
//$payment->setId('123456789'); //**
$payment->create($this->_apiContext);
//var_dump($payment); exit;
$links = $payment->getLinks();
foreach ($links as $link) {
if ($link->getMethod() == 'REDIRECT') {
$redirect_to = $link->getHref();
$token = time() . "_" . rand(100, 999);
$tmp = parse_url($redirect_to);
if (isset($tmp['query'])) {
parse_str($tmp['query'], $out);
if (isset($out['token'])) {
$token = $out['token'];
}
}
$paymentId = $payment->getId();
// ++ DEBUG LOG
$this->logging_queryes('paymentCreate_' . $paymentId . '.txt', $payment->toJSON());
// -- DEBUG LOG
return ['paymentId' => $paymentId, 'token' => $token, 'redirect_to' => $redirect_to];
}
}
return null;
}