_formDefaults = array( 'invoice' => $invoiceId, 'amount' => null, 'subtotal' => null, 'notify_url' => BASE_URL . '/' . CURRENT_PAGE . '?action=verifyOrder&type=PayPalStandard', 'custom' => array( 'no_note' => '1', 'address1' => 'Lake Street', 'city' => 'Minnetonka', 'first_name' => 'Vitalii', 'last_name' => 'Tornopilskyi', 'state' => 'MN', 'country' => 'US', 'zip' => '55305', 'custom' => '52', 'cancel_return' => BASE_URL . '/' . CURRENT_PAGE . '?action=cancelOrder&id=' . $invoiceId, 'return' => BASE_URL . '/' . CURRENT_PAGE . '?action=completeOrder&id=' . $invoiceId, ), 'itemList' => array( array( 'amount' => '150.00', 'item_name' => 'Anonymous sleeve', 'quantity' => '2' ), array( 'amount' => '50.00', 'item_name' => 'Pryanik', 'quantity' => '3' ) ), 'shipping' => '20.00', 'handling' => '7.98', 'tax' => '9.84', 'promo' => '45.00', 'giftCard' => '5.00', ); parent::__construct($options); } protected function _doInsert() { $form = $this->_getNewForm(); if ($form->validate()) { $options = $form->getValues(); $this->_prepareAmount($options); /** @var $payment App_Service_Payment_PayPalStandard */ $payment = App_Service_Payment::factory('PayPalStandard', array( 'type' => 'GET_FORM', 'data' => $options['data'], )); echo $payment->getPaymentForm()->render(); exit(); } $this->_addFormItem($form); return $this; } protected function _prepareAmount(array &$options) { $options['data']['subtotal'] = 0.0; foreach ($options['data']['itemList'] as $i) { $options['data']['subtotal'] = bcadd($options['data']['subtotal'], bcmul($i['amount'], $i['quantity'], 2), 2); } $options['data']['amount'] = 0.0; $options['data']['amount'] = bcadd($options['data']['amount'], $options['data']['subtotal'], 2); $options['data']['amount'] = bcadd($options['data']['amount'], $options['data']['tax'], 2); $options['data']['amount'] = bcadd($options['data']['amount'], $options['data']['shipping'], 2); $options['data']['amount'] = bcadd($options['data']['amount'], $options['data']['handling'], 2); $options['data']['amount'] = bcsub($options['data']['amount'], $options['data']['promo'], 2); $options['data']['amount'] = bcsub($options['data']['amount'], $options['data']['giftCard'], 2); $options['data']['shipping'] = bcadd($options['data']['shipping'], $options['data']['handling'], 2); unset($options['data']['handling']); return $this; } protected function _getNewForm() { $form = new Qs_Form($this->_getFormOptions()); $form->addElement('hidden', 'action', array('value' => 'insert')); $this->_bindFormFields($form); $form->setDefaults($this->_formDefaults); return $form; } protected function _bindFormFields(Qs_Form $form) { $mainSubForm = new Qs_Form_SubForm(); $mainSubForm->addElement('text', 'invoice', array('label' => 'Invoice #', 'required' => true)); $mainSubForm->addElement('text', 'amount', array('label' => 'Amount', 'disabled' => 'disabled')); $mainSubForm->addElement('text', 'subtotal', array('label' => 'Subtotal', 'disabled' => 'disabled')); $mainSubForm->addElement('text', 'tax', array('label' => 'Tax', 'required' => true)); $mainSubForm->addElement('text', 'promo', array('label' => 'Promo', 'required' => true)); $mainSubForm->addElement('text', 'giftCard', array('label' => 'GiftCard', 'required' => true)); $mainSubForm->addElement('text', 'shipping', array('label' => 'Shipping', 'required' => true)); $mainSubForm->addElement('text', 'handling', array('label' => 'Handling', 'required' => true)); $mainSubForm->addElement('text', 'notify_url', array('label' => 'Notify Url')); // items start $itemSubForm = new Qs_Form_SubForm(); $itemSubForm->addElement('text', 'item_name', array('label' => 'Item Name', 'required' => true)); $itemSubForm->addElement('text', 'amount', array('label' => 'Amount', 'required' => true)); $itemSubForm->addElement('text', 'quantity', array('label' => 'Quantity', 'required' => true)); $itemsForm = new Qs_Form_SubForm(); $itemsForm->addSubForm(clone $itemSubForm, '0'); $itemsForm->addSubForm(clone $itemSubForm, '1'); $mainSubForm->addSubForm($itemsForm, 'itemList'); // items finish $customSubForm = new Qs_Form_SubForm(); $customSubForm->addElement('hidden', 'no_note', array('value' => true)); $customSubForm->addElement('hidden', 'custom'); $customSubForm->addElement('text', 'address1', array('label' => 'Street Address', 'required' => true)); $customSubForm->addElement('text', 'city', array('label' => 'City', 'required' => true)); $customSubForm->addElement('text', 'state', array('label' => 'State', 'required' => true)); $customSubForm->addElement('text', 'state', array('label' => 'Country Code', 'required' => true)); $customSubForm->addElement('text', 'zip', array('label' => 'Zip', 'required' => true)); $customSubForm->addElement('text', 'first_name', array('label' => 'Zip', 'required' => true)); $customSubForm->addElement('text', 'last_name', array('label' => 'Zip', 'required' => true)); $customSubForm->addElement('text', 'cancel_return', array('label' => 'Cancel Return Url')); $customSubForm->addElement('text', 'return', array('label' => 'Return Url')); $mainSubForm->addSubForm($customSubForm, 'custom'); $form->addSubForm($mainSubForm, 'data'); return $this; } protected function _doCompleteOrder() { echo 'COMPLETE ORDER
Response:
' . print_r($_REQUEST, true) . '

'; exit(); } protected function _doCancelOrder() { echo 'CANCEL ORDER
Response:
' . print_r($_REQUEST, true) . '

'; exit(); } protected function _doVerifyOrder() { echo 'VERIFY ORDER
Response:
' . print_r($_REQUEST, true) . '

'; exit(); } }