本文整理汇总了PHP中PayPal\Api\Item::setDescription方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::setDescription方法的具体用法?PHP Item::setDescription怎么用?PHP Item::setDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Item
的用法示例。
在下文中一共展示了Item::setDescription方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPayment
private function createPayment($details)
{
$payment = new Payment();
$payer = new Payer();
$payer->payment_method = "paypal";
$amount = new Amount();
$amount->currency = $details['PAYMENTREQUEST_CURRENCYCODE'];
$amount->total = $details['PAYMENTREQUEST_AMT'];
$transaction = new Transaction();
$transaction->amount = $amount;
$transaction->description = $details['PAYMENTREQUEST_DESCRIPTION'];
$itemList = new ItemList();
foreach ($details['PAYMENTREQUEST_ITEMS'] as $itemInfo) {
$item = new Item();
$item->setQuantity($itemInfo['quantity']);
$item->setName($itemInfo['name']);
$item->setDescription($itemInfo['description']);
$item->setPrice($itemInfo['price']);
$item->setCategory($itemInfo['category']);
$item->setCurrency($itemInfo['currency']);
$item->setTax($itemInfo['tax']);
$item->setSku($itemInfo['sku']);
$itemList->addItem($item);
}
$addressInfo = $details['PAYMENTREQUEST_SHIPPING_ADDRESS'];
$shippingAddress = new ShippingAddress();
$shippingAddress->setRecipientName($addressInfo['recipient_name']);
$shippingAddress->setLine1($addressInfo['line1']);
$shippingAddress->setPostalCode($addressInfo['postal_code']);
$shippingAddress->setCity($addressInfo['city']);
$shippingAddress->setCountryCode($addressInfo['country_code']);
$itemList->setShippingAddress($shippingAddress);
$transaction->setItemList($itemList);
$redirectUrls = new RedirectUrls();
$redirectUrls->return_url = $details['RETURN_URL'];
$redirectUrls->cancel_url = $details['CANCEL_URL'];
$payment->intent = "sale";
$payment->payer = $payer;
$payment->redirect_urls = $redirectUrls;
$payment->transactions = [$transaction];
if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method) {
$paymentResponse = $payment->create($this->api);
$details->replace(['response' => $paymentResponse->toArray()]);
foreach ($paymentResponse->links as $link) {
if ($link->rel == 'approval_url') {
$details->replace(['approval_url' => $link->href]);
}
}
}
}
示例2: 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;
}
}
}
}