本文整理汇总了PHP中PayPal\Api\Item::setCurrency方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::setCurrency方法的具体用法?PHP Item::setCurrency怎么用?PHP Item::setCurrency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Item
的用法示例。
在下文中一共展示了Item::setCurrency方法的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: createItem
public static function createItem()
{
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
示例3: createItem
/**
* @param string $name
* @param int $currency
* @param int $quantity
* @param string $sku
* @param int $price
* @return Item
*/
public static function createItem($name, $currency, $quantity, $sku, $price)
{
$item = new Item();
$item->setName($name);
$item->setCurrency($currency);
$item->setQuantity($quantity);
$item->setSku($sku);
$item->setPrice($price);
return $item;
}
示例4: setPaypalItem
public function setPaypalItem($name, $currency, $quantity, $sku, $price)
{
$price = number_format($price, 2);
$item = new Item();
$item->setQuantity($quantity);
$item->setName($name);
$item->setPrice($price);
$item->setCurrency($currency);
$item->setSku($sku);
return $item;
}
示例5: CreateItem
function CreateItem($itemDetails)
{
$item = new Item();
foreach ($GLOBALS['META_DATA']['item'] as $meta) {
if (isset($itemDetails[$meta])) {
$item->{'set' . str_replace('_', '', $meta)}($itemDetails[$meta]);
}
}
// defaults
$item->setCurrency($GLOBALS['PAYPAL']['currency']);
return $item;
}
示例6: 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]);
}
}
}
}
示例7: getItemList
/**
* @return ItemList
*/
protected function getItemList()
{
$items = array();
foreach ($this->order->get_order_items() as $order_item) {
/** @var \AppZap\Payment\Model\OrderItem $order_item */
$item = new Item();
$item->setName($order_item->get_title());
$item->setQuantity($order_item->get_quantity());
$item->setSku($order_item->get_article_number());
$item->setPrice($order_item->get_price());
$item->setCurrency("EUR");
$items[] = $item;
}
$itemList = new ItemList();
$itemList->setItems($items);
return $itemList;
}
示例8: 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);
}
示例9: create
public static function create($items, Details $shippingDetails, $paymentIntent, $paymentMethod, $fi = null)
{
$payer = new Payer();
$payer->setPaymentMethod($paymentMethod);
if ($fi !== null) {
$payer->setFundingInstruments(array($fi));
}
$fullList = array();
foreach ($items as $item) {
if (!$item instanceof ItemInterface) {
throw new Exception('All the item created for the payment MUST implement the ItemInterface');
}
$singleItem = new Item();
$singleItem->setName($item->getName());
$singleItem->setSku($item->getSku());
$singleItem->setCurrency($item->getCurrency());
$singleItem->setPrice($item->getPrice());
$singleItem->setQuantity($item->getQuantity());
$fullList[] = $singleItem;
}
$itemList = new ItemList();
$itemList->setItems($fullList);
$details = $shippingDetails;
$subtotal = 0.0;
/** @var Item $singleItem */
foreach ($fullList as $singleItem) {
$subtotal += floatval($singleItem->getPrice()) * floatval($singleItem->getQuantity());
}
$details->setSubtotal($subtotal);
$total = $subtotal + floatval($details->getTax()) + floatval($details->getShipping());
$currencyMode = Validation::currencyMode($items);
$amount = new Amount();
$amount->setCurrency($currencyMode)->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList);
$payment = new Payment();
$payment->setIntent($paymentIntent)->setPayer($payer)->setTransactions(array($transaction));
return $payment;
}
示例10: 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;
}
示例11: makePaymentUsingPayPal
/**
* [makePaymentUsingPayPal description]
* @param [type] $order [description]
* @param [type] $currency [description]
* @param [type] $returnUrl [description]
* @param [type] $cancelUrl [description]
* @return [type] [description]
*/
function makePaymentUsingPayPal($order, $currency, $returnUrl, $cancelUrl)
{
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// $payee = new Payee();
// $payee->setEmail((string)$order['email_paypal']);
// Specify the payment amount.
$item = new Item();
$item->setQuantity((string) $order['quantity']);
$item->setName($order['description']);
$item->setPrice((string) $order['input_price']);
$item->setCurrency($currency);
$item->setSku($order['item_number']);
$array_item[] = $item;
if (isset($order['price_ship'])) {
$item_ship = new Item();
$item_ship->setQuantity('1');
$item_ship->setName('shipping');
$item_ship->setPrice((string) $order['price_ship']);
$item_ship->setCurrency($currency);
$item_ship->setSku('shipping');
$array_item[] = $item_ship;
}
$item_list = new ItemList();
$item_list->setItems($array_item);
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal((string) $order['total']);
//$amount->setTax()
// ###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);
$transaction->setDescription($order['description']);
$transaction->setItemList($item_list);
// $transaction->setPayee($payee);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl);
$redirectUrls->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->create($this->getApiContext());
return $payment;
}
示例12: makePaymentUsingPayPal
/**
* Create a payment using the buyer's paypal
* account as the funding instrument. Your app
* will have to redirect the buyer to the paypal
* website, obtain their consent to the payment
* and subsequently execute the payment using
* the execute API call.
*
* @param string $total payment amount in DDD.DD format
* @param string $currency 3 letter ISO currency code such as 'USD'
* @param string $paymentDesc A description about the payment
* @param string $returnUrl The url to which the buyer must be redirected
* to on successful completion of payment
* @param string $cancelUrl The url to which the buyer must be redirected
* to if the payment is cancelled
* @return \PayPal\Api\Payment
*/
function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl)
{
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// Specify the payment amount.
$amount = new Amount();
$amount->setCurrency($currency);
$amount->setTotal($total);
// ###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
$item = new Item();
$item->setQuantity(1);
$item->setName($paymentDesc);
$item->setPrice($total);
$item->setCurrency("USD");
$itemList = new ItemList();
$itemList->setItems(array($item));
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($itemList);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl);
$redirectUrls->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->create($this->getApiContext());
return $payment;
}
示例13: createItem
/**
* Creates a single PayPal item from given order product
*
* @param OrderProductInterface $orderProduct
*
* @return Item
*/
protected function createItem(OrderProductInterface $orderProduct) : Item
{
$item = new Item();
$item->setName($orderProduct->getProduct()->translate()->getName());
$item->setCurrency($orderProduct->getSellPrice()->getCurrency());
$item->setQuantity($orderProduct->getQuantity());
$item->setSku($orderProduct->getProduct()->getSku());
$item->setPrice($orderProduct->getSellPrice()->getNetAmount());
$item->setTax($orderProduct->getSellPrice()->getTaxAmount());
return $item;
}
示例14: pay
//.........这里部分代码省略.........
} else {
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) {
示例15: generateItemsList
function generateItemsList($order)
{
$currency = $this->properties->getCurrency();
$orderItems = $order->items;
$items = array();
foreach ($orderItems as $orderItem) {
$item = new Item();
$item->setName($orderItem->name);
$item->setQuantity($orderItem->quantity);
$item->setCurrency($currency);
$item->setPrice($orderItem->price);
if (isset($orderItem->sku)) {
$item->setSku($orderItem->sku);
}
$items[] = $item;
}
$itemList = new ItemList();
$itemList->setItems($items);
return $itemList;
}