本文整理汇总了PHP中PayPal\Api\ItemList::setShippingAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemList::setShippingAddress方法的具体用法?PHP ItemList::setShippingAddress怎么用?PHP ItemList::setShippingAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\ItemList
的用法示例。
在下文中一共展示了ItemList::setShippingAddress方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createItemList
public static function createItemList()
{
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::createAddress());
return $itemList;
}
示例2: createItemList
public static function createItemList()
{
/** @var Item $item */
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::getObject());
return $itemList;
}
示例3: Payer
//.........这里部分代码省略.........
$item[$i] = new Item();
$item[$i]->setName($this->encode_utf8($order->products[$i]['name']))->setCurrency($order->info['currency'])->setQuantity($order->products[$i]['qty'])->setPrice($order->products[$i]['price'])->setSku($order->products[$i]['model'] != '' ? $order->products[$i]['model'] : $order->products[$i]['id']);
$subtotal += $order->products[$i]['price'] * $order->products[$i]['qty'];
}
// set totals
if ($order_exists === false) {
if (!class_exists('order_total')) {
require_once DIR_WS_CLASSES . 'order_total.php';
}
$order_total_modules = new order_total();
$order_totals = $order_total_modules->process();
$this->get_totals($order_totals, true, $subtotal);
} else {
$this->get_totals($order->totals);
}
// set amount
$this->amount->setCurrency($order->info['currency'])->setDetails($this->details);
// set redirect
if ($order_exists === false) {
$redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')))->setCancelUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL')));
} else {
$redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link('callback/paypal/' . $this->code . '.php', 'oID=' . $order->info['order_id'] . '&key=' . md5($order->customer['email_address']), 'SSL')))->setCancelUrl($this->link_encoding(xtc_href_link('callback/paypal/' . $this->code . '.php', 'payment_error=' . $this->code . '&oID=' . $order->info['order_id'] . '&key=' . md5($order->customer['email_address']), 'SSL')));
}
if ($this->code == 'paypalinstallment') {
$redirectUrls->setReturnUrl($this->link_encoding(xtc_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'conditions=true', 'SSL')));
}
}
// set ItemList
if ($this->get_config('PAYPAL_ADD_CART_DETAILS') == '0' || $this->check_discount() === true) {
$item = array();
$item[0] = new Item();
$item[0]->setName($this->encode_utf8(MODULE_PAYMENT_PAYPAL_TEXT_ORDER))->setCurrency($_SESSION['currency'])->setQuantity(1)->setPrice($this->details->getSubtotal());
if ($cart === true) {
$shipping_cost = $this->get_config('MODULE_PAYMENT_' . strtoupper($this->code) . '_SHIPPING_COST');
if ((int) $shipping_cost > 0) {
$item[1] = new Item();
$item[1]->setName($this->encode_utf8(PAYPAL_EXP_VORL))->setCurrency($_SESSION['currency'])->setQuantity(1)->setPrice($shipping_cost);
$this->amount->setTotal($this->amount->getTotal() + $shipping_cost);
$this->details->setSubtotal($this->amount->getTotal());
}
}
}
$itemList->setItems($item);
// profile
$address_override = false;
$profile_id = $this->get_config('PAYPAL_' . strtoupper($this->code . '_' . $_SESSION['language_code']) . '_PROFILE');
if ($profile_id == '') {
$profile_id = $this->get_config('PAYPAL_STANDARD_PROFILE');
}
if ($profile_id != '') {
if ($this->get_config(strtoupper($profile_id) . '_TIME') < time() - 3600 * 24) {
$profile = $this->get_profile($profile_id);
$sql_data_array = array(array('config_key' => strtoupper($profile_id) . '_TIME', 'config_value' => time()), array('config_key' => strtoupper($profile_id) . '_ADDRESS', 'config_value' => $profile[0]['input_fields']['address_override']));
$this->save_config($sql_data_array);
$address_override = $profile[0]['input_fields']['address_override'] == '0' ? true : false;
} else {
$address_override = $this->get_config(strtoupper($profile_id) . '_ADDRESS') == '0' ? true : false;
}
}
if ($cart === false && $approval === false && $address_override === false || $order_exists === true || $this->code == 'paypalinstallment') {
$itemList->setShippingAddress($shipping_address);
}
if ($this->code == 'paypalinstallment') {
// set payment address
$payment_address = new Address();
$payment_address->setLine1($this->encode_utf8($order->billing['street_address']))->setCity($this->encode_utf8($order->billing['city']))->setState($this->encode_utf8($order->billing['state'] != '' ? xtc_get_zone_code($order->billing['country_id'], $order->billing['zone_id'], $order->billing['state']) : ''))->setPostalCode($this->encode_utf8($order->billing['postcode']))->setCountryCode($this->encode_utf8($order->billing['country']['iso_code_2']));
if ($order->billing['suburb'] != '') {
$payment_address->setLine2($this->encode_utf8($order->billing['suburb']));
}
$payer_info->setBillingAddress($payment_address)->setShippingAddress($shipping_address)->setEmail($this->encode_utf8($order->customer['email_address']))->setFirstName($this->encode_utf8($order->delivery['firstname']))->setLastName($this->encode_utf8($order->delivery['lastname']));
$payer->setPayerInfo($payer_info);
}
// set transaction
$transaction = new Transaction();
$transaction->setAmount($this->amount)->setItemList($itemList)->setDescription($this->encode_utf8(STORE_NAME))->setInvoiceNumber(uniqid());
// set payment
$payment = new Payment();
$payment->setIntent($this->transaction_type)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction))->setCreateTime(time());
if (isset($profile_id) && $profile_id != '') {
$payment->setExperienceProfileId($profile_id);
}
try {
$payment->create($apiContext);
$_SESSION['paypal']['paymentId'] = $payment->getId();
$approval_link = $payment->getApprovalLink();
if ($approval === false) {
xtc_redirect($approval_link);
} else {
return $approval_link;
}
} catch (Exception $ex) {
$this->LoggingManager->log(print_r($ex, true), 'DEBUG');
unset($_SESSION['paypal']);
if ($cart === true) {
xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART, 'payment_error=' . $this->code, 'SSL'));
} elseif ($this->code != 'paypalplus') {
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL'));
}
}
}
示例4: 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]);
}
}
}
}
示例5: buildTransaction
/**
* @return Transaction
*/
private function buildTransaction()
{
$clientInfo = ClientHelper::getClientInfo();
$priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax;
$paypalItems = [];
$subTotal = 0;
foreach ($this->order->getItems() as $item) {
/* @var $item OrderItem */
// don't add shipping row
if ($item->isShipping()) {
continue;
}
$subTotal += $item->getPrice();
$newItem = new Item();
$newItem->setName($item->getProductName())->setCurrency($clientInfo->currency->currency_iso)->setQuantity($item->getQuantity())->setSku($item->getProductSku())->setPrice($item->getPrice() / 100);
$paypalItems[] = $newItem;
}
$shippingBeforeTax = $this->order->getShipping() / 100;
$tax = $this->order->getTax() / 100;
$subTotal = $subTotal / 100;
$total = $this->order->getTotalPrice() / 100;
$orderShippingAddress = $this->order->getShippingAddress()->getArray();
$shippingAddress = new ShippingAddress();
$shippingAddress->setCity($orderShippingAddress['city']);
$shippingAddress->setCountryCode(CountryHelper::getCountryCode($orderShippingAddress['countryId']));
$shippingAddress->setPostalCode($orderShippingAddress['postcode']);
$shippingAddress->setLine1($orderShippingAddress['address1']);
$shippingAddress->setState($orderShippingAddress['state']);
$shippingAddress->setRecipientName($this->order->getCustomer()->fullName());
$itemList = new ItemList();
if (!$priceIncludesTax) {
$itemList->setItems($paypalItems);
}
$itemList->setShippingAddress($shippingAddress);
$details = new Details();
$details->setShipping($shippingBeforeTax)->setTax($tax)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency($clientInfo->currency->currency_iso)->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Order from " . $clientInfo->name)->setInvoiceNumber($this->order->getId());
return $transaction;
}
示例6: postPayment
public function postPayment(Request $request)
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item_listArr = [];
$totalAmount = 0;
if ($request->session()->has('member')) {
$memberID = $request->session()->get('member');
$memberInfo = DB::select("select * from members where email = '{$memberID}'")[0];
$shoppingCart = DB::select("select * from shopping_cart where member_id = '{$memberID}'")[0]->shopping_cart;
$shoppingCart = json_decode($shoppingCart, true);
if (sizeof($shoppingCart) == 0) {
return Redirect::to('/shoppingCart');
}
$shoppingCartItemsFinal = DB::table('products')->whereIn('product_id', array_keys($shoppingCart))->get();
foreach ($shoppingCartItemsFinal as $key => $value) {
$value->num = $shoppingCart[$value->product_id];
$priceList = json_decode($value->price, true);
$eachPrice = $value->single_price;
krsort($priceList);
foreach ($priceList as $packageNum => $price) {
if ($value->num >= $packageNum) {
$eachPrice = $price;
break;
}
}
$value->eachPrice = $eachPrice;
$item = new Item();
$item->setName($value->name)->setCurrency('AUD')->setQuantity($value->num * 1)->setPrice($eachPrice);
// unit price
array_push($item_listArr, $item);
$totalAmount += $eachPrice * $value->num;
}
} else {
$shoppingCart = json_decode($request->cookie('shoppingCart'), true);
if (sizeof($shoppingCart) == 0) {
return Redirect::to('/shoppingCart');
}
$shoppingCartItemsFinal = DB::table('products')->whereIn('product_id', array_keys($shoppingCart))->get();
foreach ($shoppingCartItemsFinal as $key => $value) {
$value->num = $shoppingCart[$value->product_id];
$priceList = json_decode($value->price, true);
$eachPrice = $value->single_price;
krsort($priceList);
foreach ($priceList as $packageNum => $price) {
if ($value->num >= $packageNum) {
$eachPrice = $price;
break;
}
}
$value->eachPrice = $eachPrice;
$item = new Item();
$item->setName($value->name)->setCurrency('AUD')->setQuantity($value->num * 1)->setPrice($eachPrice);
// unit price
array_push($item_listArr, $item);
$totalAmount += $eachPrice * $value->num;
}
}
$item_list = new ItemList();
$item_list->setItems($item_listArr);
$shipping_address = new ShippingAddress();
$payerInfo = Session::get('payment_shopping_payer_info');
$shipping_address->setCountryCode('AU');
$shipping_address->setCity($payerInfo['suburb']);
$shipping_address->setPostalCode($payerInfo['postcode']);
$shipping_address->setLine1($payerInfo['address']);
$shipping_address->setState($payerInfo['state']);
$shipping_address->setRecipientName($payerInfo['name']);
$item_list->setShippingAddress($shipping_address);
$amount = new Amount();
$amount->setCurrency('AUD')->setTotal($totalAmount);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (\Config::get('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
exit;
} else {
die('Some error occur, sorry for inconvenient');
}
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
Session::put('paypal_payment_id', $payment->getId());
if (isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
} else {
//.........这里部分代码省略.........