* $paymentTest = App_Service_Payment::factory('PayPalExpressCheckout', array( * 'type' => 'SET_EXPRESS_CHECKOUT', * 'data' => array( * 'invoice' => 12345, * 'amount' => 6.9, * 'currency' => 'USD', * 'itemList' => array( * array('L_AMT' => 2.4, 'L_NAME' => 'Name Item #1', 'L_QTY' => 1), * array('L_AMT' => 1.5, 'L_NAME' => 'Name Item #2', 'L_QTY' => 3) * ) * ) * )); * */ class App_Service_Payment_PayPalExpressCheckout_View extends Qs_ViewController { protected $_actions = ['view', 'getDetails', 'cancelPayment', 'success', 'fail']; protected $_actionTemplate; protected function _doGetDetails() { /** @var $payment App_Service_Payment_PayPalExpressCheckout */ $payment = App_Service_Payment::factory( 'PayPalExpressCheckout', [ 'type' => App_Service_Payment_PayPalExpressCheckout::GET_EXPRESS_CHECKOUT_DETAILS_TYPE, 'data' => ['token' => Qs_Request::getGetValue('token')], ] ); $params = $this->getRestParams(); if (isset($params[0]) && $payment->verifyOrder($params[0])) { /** @var $paymentResult App_Service_Payment_PayPalExpressCheckout */ $paymentResult = App_Service_Payment::factory( 'PayPalExpressCheckout', [ 'type' => App_Service_Payment_PayPalExpressCheckout::DO_EXPRESS_CHECKOUT_PAYMENT_TYPE, 'data' => [ 'token' => Qs_Request::getGetValue('token'), 'amount' => $payment->getResponse()->getData('PAYMENTREQUEST_0_AMT'), 'currency' => $payment->getResponse()->getData('PAYMENTREQUEST_0_CURRENCYCODE'), 'payerId' => $payment->getResponse()->getData('PAYERID'), ], ] ); if ($paymentResult->getResponse()->isSuccess()) { $this->_addSuccessItem(); } else { $this->_addFailItem(); }; } else { $this->_addFailItem(); } return $this; } protected function _doGetDetailsAjax() { return $this->_doGetDetails(); } protected function _addPaymentItem() { $params = $this->getRestParams(); $item = [ 'tpl' => $this->getTemplate($this->_actionTemplate), ]; if (isset($params[0])) { $item['orderId'] = $params[0]; } $this->_addItem($item); return $this; } protected function _doCancelPayment() { $this->_actionTemplate = 'cancelView.tpl'; $this->_addPaymentItem(); return $this; } protected function _addSuccessItem() { $this->_actionTemplate = 'successView.tpl'; $this->_addPaymentItem(); return $this; } protected function _addFailItem() { $this->_actionTemplate = 'failView.tpl'; $this->_addPaymentItem(); return $this; } }