'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 = array()) { $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', array('value' => $this->_getPaymentConfig('cmd'))); $this->_paymentForm->addElement( 'hidden', 'business', array('value' => $this->_getPaymentConfig('receiverEmail')) ); $notifyUrl = (!empty($data['notify_url'])) ? $data['notify_url'] : $this->_getPaymentConfig('notifyUrl'); $this->_paymentForm->addElement('hidden', 'notify_url', array('value' => $notifyUrl)); if ($this->_getPaymentConfig('upload')) { $this->_paymentForm->addElement('hidden', 'upload', array('value' => true)); } $this->_paymentForm->addElement('hidden', 'invoice', array('value' => $this->_invoice)); foreach ($this->_getItemList() as $key => $item) { foreach ($item as $name => $value) { $this->_paymentForm->addElement('hidden', $name . '_' . ($key + 1), array('value' => $value)); } } if ($data['shipping']) { $this->_paymentForm->addElement('hidden', 'handling_cart', array('value' => $data['shipping'])); } if ($data['tax']) { $this->_paymentForm->addElement('hidden', 'tax_cart', array('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', array('value' => $discount)); } $this->_paymentForm->addElement('hidden', 'address_override', array('value' => true)); if (!empty($data['custom'])) { foreach ($data['custom'] as $field => $value) { $this->_paymentForm->addElement('hidden', $field, array('value' => $value)); } } $this->_paymentForm->addElement( 'submit', 'submit', array('label' => 'Proceed to Checkout', 'attribs' => array('class' => 'btn')) ); } return $this; } public function getPaymentForm() { return $this->_paymentForm; } protected function _setInvoice($invoice) { $this->_invoice = $invoice; } }