本文整理汇总了PHP中PayPal\Api\ItemList::addItem方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemList::addItem方法的具体用法?PHP ItemList::addItem怎么用?PHP ItemList::addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\ItemList
的用法示例。
在下文中一共展示了ItemList::addItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRemoveItemMethod
public function testRemoveItemMethod()
{
$itemList = new ItemList();
$item1 = ItemTest::createItem();
$item1->setName("Name1");
$item2 = ItemTest::createItem();
$itemList->addItem($item1);
$itemList->addItem($item2);
$itemList->removeItem($item2);
$this->assertEquals(sizeof($itemList->getItems()), 1);
$remainingElements = $itemList->getItems();
$this->assertEquals($remainingElements[0]->getName(), "Name1");
}
示例2: init
/**
* @param PaymentInterface $payment
*/
public function init(PaymentInterface $payment)
{
$credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
$apiContext = new ApiContext($credentials);
$apiContext->setConfig(['mode' => $this->options['mode']]);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency($this->options['currency']);
$amount->setTotal($payment->getPaymentSum());
$item = new Item();
$item->setName($payment->getDescription());
$item->setCurrency($amount->getCurrency());
$item->setQuantity(1);
$item->setPrice($amount->getTotal());
$itemList = new ItemList();
$itemList->addItem($item);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($payment->getDescription());
$transaction->setItemList($itemList);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($payment->getExtraData('return_url'));
$redirectUrls->setCancelUrl($payment->getExtraData('cancel_url'));
$paypalPayment = new Payment();
$paypalPayment->setIntent('sale');
$paypalPayment->setPayer($payer);
$paypalPayment->setTransactions([$transaction]);
$paypalPayment->setRedirectUrls($redirectUrls);
$paypalPayment->create($apiContext);
$payment->setExtraData('paypal_payment_id', $paypalPayment->getId());
$payment->setExtraData('approval_link', $paypalPayment->getApprovalLink());
}
示例3: 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]);
}
}
}
}
示例4: start
public function start()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$itemList = new ItemList();
$productsSum = 0.0;
foreach ($this->order->getProducts() as $product) {
$item = new Item();
$item->setName($product->getName())->setCurrency($this->order->getCurrency())->setQuantity($product->getQuantity())->setSku($product->getSku())->setPrice($product->getPrice());
$itemList->addItem($item);
$productsSum += $product->getTotal();
}
$details = new Details();
$details->setSubtotal($productsSum);
$total = $productsSum;
if ($delivery = $this->order->getDelivery()) {
$details->setShipping($delivery);
$total += $delivery;
}
if ($vat = $this->order->getVat()) {
$details->setTax($vat);
$total += $vat;
}
$amount = new Amount();
$amount->setCurrency($this->order->getCurrency())->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription($this->order->getDescription())->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(env('DOMAIN') . url($this->config['url_return'], ['paypalRest', $this->order->getOrder()]))->setCancelUrl(env('DOMAIN') . url($this->config['url_cancel'], ['paypalRest', $this->order->getOrder()]));
$payment = new Payment();
$payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
try {
$this->log($payment);
$payment->create($this->paypal);
$this->log($payment);
} catch (\Exception $e) {
$this->log($e);
throw $e;
} finally {
redirect()->away($payment->getApprovalLink())->send();
}
}
示例5: process
public function process($orderData, $cartProducts = [])
{
$this->setApiContext();
$this->_apiContext->setConfig(['mode' => Configuration::getConfiguration('paypal_payment_mode'), 'service.EndPoint' => Configuration::getConfiguration('paypal_payment_url'), 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => Configuration::getConfiguration('paypal_payment_log'), 'log.FileName' => storage_path('logs/paypal.log'), 'log.LogLevel' => 'FINE']);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$itemList = new ItemList();
$subTotal = 0;
$taxTotal = 0;
foreach ($cartProducts as $product) {
$item = new Item();
$model = $product['model'];
$item->setName($model->title)->setCurrency('USD')->setQuantity($product['qty'])->setSku($model->sku)->setPrice($product['price']);
$itemList->addItem($item);
$subTotal += $product['price'] * $product['qty'];
$taxTotal += $product['tax_amount'] * $product['qty'];
}
$total = $subTotal + $taxTotal;
$shippingOption = $orderData['shipping_method'];
$shipping = Shipping::get($shippingOption);
$details = new Details();
$details->setShipping($shipping->getAmount())->setTax($taxTotal)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency('USD')->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment description')->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(route('paypal.store'));
$redirectUrls->setCancelUrl(route('paypal.cancel'));
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions([$transaction]);
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return $redirectUrl;
}
示例6: createItemList
/**
* Creates a collection of PayPal items for given order
*
* @param OrderInterface $order
*
* @return ItemList
*/
protected function createItemList(OrderInterface $order) : ItemList
{
$itemList = new ItemList();
$order->getProducts()->map(function (OrderProductInterface $orderProduct) use($itemList) {
$itemList->addItem($this->createItem($orderProduct));
});
return $itemList;
}
示例7: addItem
/**
* Add an item detail for the order you are creating
* @param string $sku The internal item code
* @param string $name Item title
* @param integer $quantity Item quantity
* @param float $price Item total price
*/
public function addItem($sku, $name, $quantity, $price)
{
$item = new Item();
$item->setName($name)->setCurrency($this->getCurrency())->setQuantity($quantity)->setSku($sku)->setPrice($price);
$this->itemList->addItem($item);
}
示例8: pay
public function pay(array $items = null, $invoiceNo = null)
{
if (!isset($invoiceNo)) {
$invoiceNo = uniqid();
}
if (isset($items) && !empty($items)) {
$baseUrl = SYMPHONY_URL . '/extension/paypal/payment';
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$itemList = new ItemList();
$subTotal = 0;
$taxTotal = 0;
$shipping = 0;
foreach ($items as $key => $itemDetails) {
$subTotal += $itemDetails['price'];
if (isset($itemDetails['tax'])) {
$taxTotal += $itemDetails['tax'];
}
$itemList->addItem($this->paypalItemFromArray($itemDetails));
}
$details = new Details();
$details->setShipping($shipping)->setTax($taxTotal)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency($this->currency)->setTotal($subTotal + $taxTotal)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("JCI Malta Membership")->setInvoiceNumber($invoiceNo);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}?success=true")->setCancelUrl("{$baseUrl}?success=false");
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($this->apiContext);
} catch (Exception $ex) {
var_dump($request);
var_dump($ex);
die;
return "error";
//log the error
// echo("Error Creating Payment Using PayPal.", "Payment", null, $request, $ex);
// exit(1);
}
$return = array('id' => $payment->getId(), 'link' => $payment->getApprovalLink());
return $return;
}
}
示例9: 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;
}
}
}
}
示例10: paypal
public function paypal(Request $request)
{
$apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD'));
// ### Payer
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
$item1 = new Item();
$item1->setName($request->nome)->setCurrency('BRL')->setQuantity($request->quantidade)->setSku($request->acao)->setPrice($request->valor);
$itemList = new ItemList();
$itemList->addItem($item1);
// ### Additional payment details
$shipping = 0 * $request->total;
$tax = 0 * $request->total;
$details = new Details();
$details->setShipping($shipping)->setTax($tax)->setSubtotal($request->valor * $request->quantidade);
// ### Amount
$amount = new Amount();
$amount->setCurrency("BRL")->setTotal($request->total + $tax + $shipping)->setDetails($details);
// ### Transaction
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("{$request->rifas}")->setInvoiceNumber(uniqid());
// ### Redirect urls
$baseUrl = "http://localhost:8000/confirmacao";
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("{$baseUrl}/?success=true&")->setCancelUrl("{$baseUrl}/?success=false");
// ### Payment
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
// // For Sample Purposes Only.
// $request = clone $payment;
// ### Create Payment
try {
$payment->create($apiContext);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
// Prints the Error Code
echo $ex->getData();
// Prints the detailed error message
die($ex);
} catch (Exception $ex) {
die($ex);
}
$approvalUrl = $payment->getApprovalLink();
echo "Created Payment Using PayPal. Please visit the URL to Approve.";
return redirect($approvalUrl);
}