当前位置: 首页>>代码示例>>PHP>>正文


PHP Payment::toArray方法代码示例

本文整理汇总了PHP中PayPal\Api\Payment::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Payment::toArray方法的具体用法?PHP Payment::toArray怎么用?PHP Payment::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PayPal\Api\Payment的用法示例。


在下文中一共展示了Payment::toArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: catch

$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
// ### Create Payment
// Create a payment by posting to the APIService
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the status;
try {
    $payment->create($apiContext);
} catch (\PPConnectionException $ex) {
    echo "Exception: " . $ex->getMessage() . PHP_EOL;
    var_dump($ex->getData());
    exit(1);
}
?>
<html>
<body>
	<div>
		Created payment:
		<?php 
echo $payment->getId();
?>
	</div>
	<pre><?php 
var_dump($payment->toArray());
?>
</pre>
	<a href='../index.html'>Back</a>
</body>
</html>
开发者ID:Lucerin,项目名称:Yii-projects,代码行数:30,代码来源:CreatePayment.php

示例2: callback

 /**
  * Callback method
  *
  * @param array $data
  * @return array
  */
 public function callback($data = array())
 {
     $app = App::getInstance('zoo');
     $joomla = JFactory::getApplication();
     $data = $this->app->request->get('pp', 'array');
     // Configure:
     $apiContext = new ApiContext(new OAuthTokenCredential($this->params->get('client_id', ''), $this->params->get('secret', '')));
     $apiContext->setConfig(array('mode' => $this->params->get('test', 0) ? 'sandbox' : 'live', 'http.ConnectionTimeOut' => 60, 'log.LogEnabled' => false));
     // Retrieve order data:
     $order = $app->zoocart->table->orders->get((int) $data['order_id']);
     $status = 0;
     $transaction_id = '';
     if (!empty($order)) {
         // Process payment:
         // Create credit card:
         $card = new CreditCard();
         $card->setType($data['cardtype'])->setNumber($data['cardnumber'])->setExpireMonth($data['month'])->setExpireYear($data['year'])->setCvv2($data['cvv'])->setFirstName($data['firstname'])->setLastName($data['lastname']);
         $fi = new FundingInstrument();
         $fi->setCreditCard($card);
         // Create Payer:
         $payer = new Payer();
         $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
         $orderitems = $order->getItems();
         if (!empty($orderitems)) {
             $list = array();
             $itemList = new ItemList();
             $totalProductsAmount = 0;
             foreach ($orderitems as $order_item) {
                 $item = new Item();
                 $item->setName($order_item->name)->setCurrency($order->getCurrency()->code)->setQuantity($order_item->quantity)->setPrice(money_format('%.2n', round($order_item->price, 2)));
                 $totalProductsAmount += round($order_item->price, 2);
                 $list[] = $item;
             }
             //add payment fee as product
             if ($order->payment) {
                 $item = new Item();
                 $item->setName(JText::_('PLG_ZOOCART_PAYMENT_PAYPALPRO_FEE_LABEL'))->setCurrency($order->getCurrency()->code)->setQuantity(1)->setPrice(money_format('%.2n', round($order->payment, 2)));
                 $totalProductsAmount += round($order->payment, 2);
                 $list[] = $item;
             }
             //add discount as a product
             if ($order->payment) {
                 $item = new Item();
                 $item->setName(JText::_('PLG_ZOOCART_PAYMENT_PAYPALPRO_DISCOUNT_LABEL'))->setCurrency($order->getCurrency()->code)->setQuantity(1)->setPrice(money_format('%.2n', round(0 - $order->discount, 2)));
                 $totalProductsAmount += round(0 - $order->discount, 2);
                 $list[] = $item;
             }
             $itemList->setItems($list);
         }
         $details = new Details();
         $details->setShipping(money_format('%.2n', round($order->shipping, 2)))->setTax(money_format('%.2n', round($order->getTaxTotal(), 2)))->setSubtotal(money_format('%.2n', round($totalProductsAmount, 2)));
         $amount = new Amount();
         $amount->setCurrency($order->getCurrency()->code)->setTotal(money_format('%.2n', $order->getTotal()))->setDetails($details);
         // Create transaction:
         $transaction = new Transaction();
         $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Order #" . (int) $order->id . " payment");
         // Create payment:
         $payment = new Payment();
         $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
         try {
             $payment->create($apiContext);
             $response = $payment->toArray();
             $response['order_total'] = $order->getTotal();
             if (!$this->isValidIPN($response)) {
                 $joomla->enqueueMessage(JText::_('PLG_ZOOCART_PAYPALPRO_INVALID_IPN'), 'error');
                 return;
             }
             $transaction_id = $response['id'];
             if ($response['state'] == 'approved') {
                 $status = 1;
             }
         } catch (PayPal\Exception\PPConnectionException $ex) {
             $joomla->enqueueMessage(JText::sprintf('PLG_ZOOCART_PAYPALPRO_GOT_EXCEPTION', $ex->getMessage()), 'error');
         }
     } else {
         // No order found exception
     }
     return array('status' => $status, 'transaction_id' => $transaction_id, 'order_id' => $order->id, 'total' => $order->getTotal());
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:85,代码来源:paypalpro.php


注:本文中的PayPal\Api\Payment::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。