本文整理汇总了PHP中PayPal\Api\Payment::toJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP Payment::toJSON方法的具体用法?PHP Payment::toJSON怎么用?PHP Payment::toJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Payment
的用法示例。
在下文中一共展示了Payment::toJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pay
//.........这里部分代码省略.........
if ($paymentChoice === "cash") {
$paymentID = "CASH-" . $this->randomString();
$this->paypal_history_model->add($paymentID, $userID, $_COOKIE['cart'], "", $this->time->get_timestamp(), "created");
// Aggiungiamo la pre-iscrizione al DB (se necessario)
foreach ($cartItems as $item) {
$courseID = $item['courseID'];
$payment = $this->payment_model->get_payment($userID, $courseID);
if (empty($payment)) {
$this->payment_model->add($userID, $courseID);
}
}
sleep(3);
echo json_encode(array("error" => false, "url" => "index.php/Paypal/payment_successful?paymentId=" . $paymentID . "&PayerID=" . $userID));
return;
} else {
if ($paymentChoice === "creditCard") {
$userInfo = $this->userinfo_model->get($userID);
$payer = new Payer();
$payerInfo = new PayerInfo();
if (array_key_exists('name', $userInfo)) {
$payerInfo->setFirstName($userInfo['name']);
}
if (array_key_exists('surname', $userInfo)) {
$payerInfo->setLastName($userInfo['surname']);
}
if (array_key_exists('birthdate', $userInfo)) {
$payerInfo->setBirthDate($userInfo['birthdate']);
}
$payerInfo->setPayerId($userID);
$payer->setPayerInfo($payerInfo);
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency('EUR');
$amount->setTotal($total);
$transaction = new Transaction();
$transaction->setAmount($amount);
$itemList = new ItemList();
foreach ($totalItems as $cartItem) {
$item = new Item();
$item->setName($cartItem['item']);
$item->setDescription($cartItem['description']);
$item->setQuantity(1);
$item->setCurrency("EUR");
$item->setPrice($cartItem['price']);
$itemList->addItem($item);
}
$transaction->setItemList($itemList);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
// Set redirects URLs
$redirectUrls = new RedirectUrls();
$baseUrl = "https://www.reseed.it/index.php/";
$redirectUrls->setReturnUrl($baseUrl . "Paypal/payment_successful")->setCancelUrl($baseUrl . "Paypal/payment_cancelled");
$payment->setRedirectUrls($redirectUrls);
try {
// Prendiamo i docenti di tutti i corsi
$all_teachers = array();
foreach ($this->course_teachers_model->get_all_teachers() as $course_teacher) {
$all_teachers[$course_teacher['courseID']] = $course_teacher['teacherID'];
}
// Vediamo quali sono i docenti coinvolti dal pagamento dell'utente
$course_teachers = array();
foreach ($cartItems as $cartItem) {
if ($cartItem['payCourse'] == "1" || $cartItem['paySimulation'] == "1") {
$teacher = $all_teachers[$cartItem['courseID']];
if (!array_key_exists($teacher, $course_teachers)) {
$course_teachers[] = $teacher;
}
}
}
$teacher = null;
if (count($course_teachers) == 1) {
$teacher = $course_teachers[0];
}
$apiContext = $this->get_credentials($teacher);
// print("USING CREDENTIALS: ");
// print_r($apiContext);
$response = $payment->create($apiContext);
// Salva sul DB il successo
$this->paypal_history_model->add($response->getId(), $userID, json_encode($payment->toJSON()), json_encode($response->toJSON()), $this->time->get_timestamp(), $response->getState());
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo json_encode(array("error" => true, "description" => "Errore durante la connessione a Paypal. Riprova più tardi. Dettagli errore: " . $ex->getData(), "errorCode" => "PAYPAL_ERROR", "parameters" => array("")));
return;
}
// Aggiungiamo la pre-iscrizione al DB (se necessario)
foreach ($cartItems as $item) {
$courseID = $item['courseID'];
$payment = $this->payment_model->get_payment($userID, $courseID);
if (empty($payment)) {
$this->payment_model->add($userID, $courseID);
}
}
echo json_encode(array("error" => false, "url" => $response->getApprovalLink()));
return;
}
}
}
}
示例2: testMultipleEmptyArrayConversion
public function testMultipleEmptyArrayConversion()
{
$json = '{"id":"PAY-5DW86196ER176274EKT3AEYA","transactions":[{"related_resources":[{},{}]}]}';
$payment = new Payment($json);
$result = $payment->toJSON();
$this->assertContains('"related_resources":[{},{}]', $result);
$this->assertNotNull($result);
}
示例3: 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;
}