本文整理汇总了PHP中PayPal\Api\Transaction::setItemList方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::setItemList方法的具体用法?PHP Transaction::setItemList怎么用?PHP Transaction::setItemList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Transaction
的用法示例。
在下文中一共展示了Transaction::setItemList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: createPayment
/**
* Create the Payment request and process
* @return null|string The approval url to which the user has to be redirected
*/
public function createPayment()
{
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$this->validateData();
if (!is_null($this->details)) {
$this->getAmount()->setDetails($this->details);
}
$transaction = new Transaction();
$transaction->setAmount($this->getAmount())->setDescription($this->getDescription())->setInvoiceNumber($this->getInvoiceNumber());
if (count($this->itemList->getItems())) {
$transaction->setItemList($this->itemList);
}
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->getSuccessUrl(self::paymentMethod))->setCancelUrl($this->getCancelUrl(self::paymentMethod));
$payment = new Payment();
$payment->setIntent(self::ACTION)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
try {
$payment->create($this->getApiContext($this->clientId, $this->clientSecret));
} catch (\Exception $ex) {
$this->container->get('logger')->error($ex);
return null;
}
$approvalUrl = $payment->getApprovalLink();
return $approvalUrl;
}
示例3: createTransaction
/**
* Creates a PayPal transaction object for given order
*
* @param OrderInterface $order
*
* @return Transaction
*/
protected function createTransaction(OrderInterface $order) : Transaction
{
$transaction = new Transaction();
$transaction->setAmount($this->createAmount($order));
$transaction->setItemList($this->createItemList($order));
$transaction->setDescription($order->getId());
return $transaction;
}
示例4: createTransaction
/**
* @param Amount $amount
* @param ItemList $itemLists
* @param string $invoiceNumber
* @param string $description
*
* @return Transaction
*/
public static function createTransaction(Amount $amount, ItemList $itemLists, $invoiceNumber, $description)
{
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemLists);
$transaction->setInvoiceNumber($invoiceNumber);
$transaction->setDescription($description);
return $transaction;
}
示例5: createTransaction
public static function createTransaction()
{
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources(array(RelatedResourcesTest::createRelatedResources()));
return $transaction;
}
示例6: createTransaction
public static function createTransaction()
{
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setInvoiceNumber(self::$invoiceNumber);
$transaction->setCustom(self::$custom);
$transaction->setSoftDescriptor(self::$softDescriptor);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources(array(RelatedResourcesTest::createRelatedResources()));
return $transaction;
}
示例7: getTransactions
/**
* @return array array of PayPal\Api\Transaction
*/
protected function getTransactions()
{
$payPalItems = array();
$currency = $this->currency ? $this->currency : $this->context->getCurrency();
$payPalItem = new Item();
$payPalItem->setName($this->name);
$payPalItem->setCurrency($currency);
$payPalItem->setQuantity($this->quantity);
$payPalItem->setPrice($this->price);
$payPalItems[] = $payPalItem;
$totalPrice = $this->quantity * $this->price;
$itemLists = new ItemList();
$itemLists->setItems($payPalItems);
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($totalPrice);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemLists);
return array($transaction);
}
示例8: get_payment_url
/**
* When you have configured the payment properly this will give you a URL that you can redirect your visitor to,
* so that he can pay the desired amount.
*
* @param string $url_format
* @return string
*/
public function get_payment_url($url_format)
{
if (!is_array($this->payment_provider_auth_config[self::PROVIDER_NAME]) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid']) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['secret'])) {
throw new \Exception('Auth Config for Provider ' . self::PROVIDER_NAME . ' is not set.', 1394795187);
}
$total_price = $this->order->get_total_price();
if ($total_price == 0) {
throw new \Exception('Total price is 0. Provider ' . self::PROVIDER_NAME . ' does not support free payments.', 1394795478);
}
$api_context = new ApiContext(new OAuthTokenCredential($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid'], $this->payment_provider_auth_config[self::PROVIDER_NAME]['secret']));
$api_context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => false));
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency("EUR");
$amount->setTotal($this->order->get_total_price());
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($this->order->get_reason());
$transaction->setItemList($this->getItemList());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->get_success_url($url_format));
$redirectUrls->setCancelUrl($this->get_abort_url($url_format));
$payment = new \PayPal\Api\Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$payment->create($api_context);
$payment_url = '';
foreach ($payment->getLinks() as $link) {
/** @var \PayPal\Api\Links $link */
if ($link->getRel() == 'approval_url') {
$payment_url = $link->getHref();
}
}
return $payment_url;
}
示例9: callCreate
public function callCreate($clientId, $clientSecret, $orderId, $amount, $currency, $description, $returnUrl, $cancelUrl)
{
$oauthCredential = new OAuthTokenCredential($clientId, $clientSecret);
$apiContext = new ApiContext($oauthCredential);
$apiContext->setConfig(['mode' => $this->mode]);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($description);
$item->setCurrency($currency);
$item->setPrice($amount);
$item->setQuantity(1);
$itemList = new ItemList();
$itemList->setItems(array($item));
$amountObject = new Amount();
$amountObject->setCurrency($currency);
$amountObject->setTotal($amount);
$transaction = new Transaction();
$transaction->setItemList($itemList);
$transaction->setAmount($amountObject);
$transaction->setDescription($description);
$transaction->setInvoiceNumber($orderId);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try {
$payment->create($apiContext);
} catch (\Exception $e) {
throw new PaymentException('PayPal Exception: ' . $e->getMessage());
}
$approvalUrl = $payment->getApprovalLink();
return $approvalUrl;
}
示例10: array
function get_approvalurl()
{
try {
// try a payment request
$PaymentData = AngellEYE_Gateway_Paypal::calculate(null, $this->send_items);
$OrderItems = array();
if ($this->send_items) {
foreach ($PaymentData['order_items'] as $item) {
$_item = new Item();
$_item->setName($item['name'])->setCurrency(get_woocommerce_currency())->setQuantity($item['qty'])->setPrice($item['amt']);
array_push($OrderItems, $_item);
}
}
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(add_query_arg(array('pp_action' => 'executepay'), home_url()));
$redirectUrls->setCancelUrl($this->cancel_url);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$details = new Details();
if (isset($PaymentData['shippingamt'])) {
$details->setShipping($PaymentData['shippingamt']);
}
if (isset($PaymentData['taxamt'])) {
$details->setTax($PaymentData['taxamt']);
}
$details->setSubtotal($PaymentData['itemamt']);
$amount = new Amount();
$amount->setCurrency(PP_CURRENCY);
$amount->setTotal(WC()->cart->total);
$amount->setDetails($details);
$items = new ItemList();
$items->setItems($OrderItems);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('');
$transaction->setItemList($items);
//$transaction->setInvoiceNumber($this->invoice_prefix.$order_id);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->create($this->getAuth());
$this->add_log(print_r($payment, true));
//if payment method was PayPal, we need to redirect user to PayPal approval URL
if ($payment->state == "created" && $payment->payer->payment_method == "paypal") {
WC()->session->paymentId = $payment->id;
//set payment id for later use, we need this to execute payment
return $payment->links[1]->href;
}
} catch (PayPal\Exception\PayPalConnectionException $ex) {
wc_add_notice(__("Error processing checkout. Please try again. ", 'woocommerce'), 'error');
$this->add_log($ex->getData());
} catch (Exception $ex) {
wc_add_notice(__('Error processing checkout. Please try again. ', 'woocommerce'), 'error');
$this->add_log($ex->getMessage());
}
}
示例11: 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;
}
示例12: substr
/**
* @param $data array form post data
* @return string HTML to display
*/
function _prePayment($data)
{
$this->_autoload();
$order = $this->_getOrder($data['order_number']);
//initialise application
$app = JFactory::getApplication();
//get card input
$data['cardtype'] = $app->input->getString("cardtype");
$data['cardnum'] = $app->input->getString("cardnum");
$month = $app->input->getString("month");
$year = $app->input->getString("year");
$card_exp = $month . '' . $year;
$data['cardexp'] = $card_exp;
$data['cardcvv'] = $app->input->getString("cardcvv");
$data['cardnum_last4'] = substr($app->input->getString("cardnum"), -4);
//initialise payment
$apiContext = new ApiContext(new OAuthTokenCredential($this->api_clientId, $this->api_clientSecret));
$apiContext->setConfig(array('mode' => $this->api_mode));
// echo'<pre>';print_r($apiContext);die;
$card = new CreditCard();
$card->setType($data['cardtype']);
$card->setNumber($data['cardnum']);
$card->setExpireMonth($month);
$card->setExpireYear($year);
$card->setFirstName($data['firstname']);
$card->setLastName($data['lastname']);
$card->setCvv2($data['cardcvv']);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
if (!empty($data['email'])) {
$payerInfo = new PayerInfo();
$payerInfo->setFirstName($data['firstname']);
$payerInfo->setLastName($data['lastname']);
$payerInfo->setEmail($data['email']);
$payer->setPayerInfo($payerInfo);
}
$amount = new Amount();
$amount->setCurrency($this->currency);
$amount->setTotal($data['total']);
$item1 = new Item();
$item1->setName($data['order_number'])->setDescription($data['order_number'])->setCurrency($this->currency)->setQuantity(1)->setTax(0)->setPrice($data['total']);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
$transaction->setDescription($data['order_number']);
$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
$error = json_decode($ex->getData());
$error_html = '<h2>' . $error->name . '</h2><br>';
foreach ($error->details as $r) {
$error_html .= '- ' . $r->field . ' - ' . $r->issue . '<br>';
}
$app->enqueueMessage($error_html, 'error');
$app->redirect('index.php?option=com_bookpro&view=formpayment&order_id=' . $order->id . '&' . JSession::getFormToken() . '=1');
return;
} catch (Exception $ex) {
die($ex);
}
$ack = $payment->getState();
if ($ack == 'approved' || $ack == 'completed') {
$order->pay_status = "SUCCESS";
$order->order_status = "CONFIRMED";
$order->tx_id = $payment->getId();
$order->store();
} else {
JLog::addLogger(array('text_file' => 'paypal.txt', 'text_file_path' => 'logs', 'text_file_no_php' => 1, 'text_entry_format' => '{DATE} {TIME} {MESSAGE}'), JLog::ALERT);
JLog::add('Transaction: ' . json_encode($payment) . '\\nOrder: ' . $order->order_number . ' Status: ' . $ack, JLog::ALERT, 'com_bookpro');
$order->pay_status = "PENDING";
$order->tx_id = $transaction_id;
$order->store();
}
$app = JFactory::getApplication();
$app->redirect('index.php?option=com_bookpro&controller=payment&task=postpayment&method=' . $this->_element . '&order_number=' . $order->order_number);
return;
}
示例13: createTransaction
public function createTransaction(Amount $amount, $paymentDesc, ItemList $itemList = null)
{
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction();
$transaction->setAmount($amount)->setDescription($paymentDesc);
if (isset($itemList)) {
$transaction->setItemList($itemList);
}
return $transaction;
}
示例14: createPayment
public function createPayment($addressee, $order)
{
// Order Totals
$subTotal = $order->total;
$shippingCharges = $order->shipping;
$tax = $order->tax;
$grandTotal = $order->grandTotal;
// Get Context
$context = $this->getApiContext();
// Payer
$payer = new Payer();
$payer->setPaymentMethod('paypal');
// Cart Items
$itemList = $this->generateItemsList($order);
// Shipping Address
if ($this->properties->isSendAddress()) {
$shippingAddress = $this->generateShippingAddress($addressee, $cart);
$itemList->setShippingAddress($shippingAddress);
}
// Details
$details = new Details();
$details->setSubtotal($subTotal);
$details->setShipping($shippingCharges);
$details->setTax($tax);
// Amount
$amount = new Amount();
$amount->setCurrency($this->properties->getCurrency());
$amount->setTotal($grandTotal);
$amount->setDetails($details);
// Transaction
$transaction = new Transaction();
$transaction->setAmount($amount);
if (isset($order->description)) {
$transaction->setDescription($order->description);
}
$transaction->setItemList($itemList);
// Status URLs
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($this->successUrl);
$redirectUrls->setCancelUrl($this->failureUrl);
// Payment
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions([$transaction]);
$payment->create($context);
return $payment;
}
示例15: 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;
}
}
}
}