'GET_FORM', * 'data' => array( * 'invoice' => 12345, * 'itemList' => array( * array('amount' => 2.4, 'item_name' => 'Name Item #1', 'quantity' => 1), * array('amount' => 1.5, 'item_name' => 'Name Item #2', 'quantity' => 3) * ) * ) * )); * $form = $paymentTest->getPaymentForm(); */ class App_Service_Payment_PayPalStandard extends App_Service_Payment_Abstract { const GET_FORM_TYPE = 'GET_FORM'; const DEFAULT_PAYMENT_TYPE = self::GET_FORM_TYPE; protected $_paymentType = self::DEFAULT_PAYMENT_TYPE; protected $_logFileName = 'payPalStandard'; protected $_paymentConfigAlias = 'Service_Payment_PayPalStandard'; /** @var Qs_Form */ protected $_paymentForm; protected $_invoice; function __construct($options = []) { $invoice = Qs_Array::get($options, 'data[invoice]'); if ($invoice) { $this->_setInvoice($invoice); } parent::__construct($options); if ($this->getPaymentType() == self::GET_FORM_TYPE) { return $this->_createPaymentForm(); } else if ($this->getPaymentType() == self::VERIFY_IPN_TYPE) { $this->_verifyIpn(); } return $this; } protected function _createPaymentForm() { if (!$this->_paymentForm) { $data = $this->getOption('data'); $this->_paymentForm = new Zend_Form(); $this->_paymentForm->setAction($this->_getPaymentConfig('actionUrl')); $this->_paymentForm->addElement('hidden', 'cmd', ['value' => $this->_getPaymentConfig('cmd')]); $this->_paymentForm->addElement( 'hidden', 'business', ['value' => $this->_getPaymentConfig('receiverEmail')] ); $notifyUrl = (!empty($data['notify_url'])) ? $data['notify_url'] : $this->_getPaymentConfig('notifyUrl'); $this->_paymentForm->addElement('hidden', 'notify_url', ['value' => $notifyUrl]); if ($this->_getPaymentConfig('upload')) { $this->_paymentForm->addElement('hidden', 'upload', ['value' => true]); } $this->_paymentForm->addElement('hidden', 'invoice', ['value' => $this->_invoice]); foreach ($this->_getItemList() as $key => $item) { foreach ($item as $name => $value) { $this->_paymentForm->addElement('hidden', $name . '_' . ($key + 1), ['value' => $value]); } } if ($data['shipping']) { $this->_paymentForm->addElement('hidden', 'handling_cart', ['value' => $data['shipping']]); } if ($data['tax']) { $this->_paymentForm->addElement('hidden', 'tax_cart', ['value' => $data['tax']]); } if (Qs_Array::get($data, 'promo') || Qs_Array::get($data, 'giftCard')) { $discount = Zend_Locale_Math::Add($data['promo'], $data['giftCard'], 2); $this->_paymentForm->addElement('hidden', 'discount_amount_cart', ['value' => $discount]); } $this->_paymentForm->addElement('hidden', 'address_override', ['value' => true]); if (!empty($data['custom'])) { foreach ($data['custom'] as $field => $value) { $this->_paymentForm->addElement('hidden', $field, ['value' => $value]); } } $this->_paymentForm->addElement( 'submit', 'submit', ['label' => 'Proceed to Checkout', 'attribs' => ['class' => 'btn']] ); } return $this; } public function getPaymentForm() { return $this->_paymentForm; } protected function _setInvoice($invoice) { $this->_invoice = $invoice; } }