public function createForm($label, $cc_mask = null) { $form = new Am_Form('cc-paymill'); $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card')); $name->addRule('required', ___('Please enter credit card holder name')); $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f')); $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|'); $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l')); $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|'); $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444')); if ($cc_mask) { $cc->setAttribute('placeholder', $cc_mask); } $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/'); class_exists('Am_Form_CreditCard', true); // preload element $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year')); $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>')); $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/'); /**/ $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)')); $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address')); $city = $fieldSet->addText('cc_city')->setLabel(___('City'))->addRule('required', ___('Please enter City')); $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code')); $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true)); $country->addRule('required', ___('Please enter Country')); $group = $fieldSet->addGroup()->setLabel(___('State')); $group->addRule('required', ___('Please enter State')); $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true)); $stateText = $group->addText('cc_state')->setId('t_cc_state'); $disableObj = $stateOptions ? $stateText : $stateSelect; $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none'); /**/ $form->addSubmit('', array('value' => $label)); $form->addHidden('id')->setValue($this->_request->get('id')); $form->addHidden('paymill_token', 'id=paymill_token')->addRule('required'); //$key = json_encode($this->plugin->getConfig('public_key')); $key = $this->plugin->getConfig('public_key'); $amount = $this->invoice->isFirstPayment() ? $this->invoice->first_total : $this->invoice->second_total; $amount = sprintf('%.02f', $amount) * 100; $form->addProlog('<script type="text/javascript" src="https://bridge.paymill.com/"></script>'); $form->addScript()->setScript("var PAYMILL_PUBLIC_KEY = '" . $key . "';"); if ($this->testMode) { $form->addScript()->setScript("var PAYMILL_TEST_MODE = true;"); } $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js')); $form->addScript()->setScript(<<<CUT jQuery(function(\$){ \$("form#cc-paymill").submit(function(event){ var frm = \$(this); \$('.submit-button').attr("disabled", "disabled"); if (frm.find("input[name=paymill_token]").val() > '') return true; // submit the form! event.stopPropagation(); paymill.createToken({ number: frm.find("#cc_number").val(), // required exp_month: frm.find("[name='cc_expire[m]']").val(), // required exp_year: frm.find("[name='cc_expire[y]']").val(), // required cvc: frm.find("#cc_code").val(), // required amount_int: {$amount}, // required, z.B. "4900" for 49.00 EUR currency: '{$this->invoice->currency}', // required cardholder: frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val() // optional }, function(error, result){ // handle response if (error) { frm.find("input[type=submit]").prop('disabled', null); var el = frm.find("#cc_number"); var cnt = el.closest(".element"); cnt.addClass("error"); cnt.find("span.error").remove(); var errorMessage = ''; switch (error.apierror) { case 'internal_server_error': errorMessage = 'Communication with PSP failed'; break; case 'invalid_public_key': errorMessage = 'Invalid Public Key'; break; case 'unknown_error': errorMessage = 'Unknown Error'; break; case '3ds_cancelled': errorMessage = 'Password Entry of 3-D Secure password was cancelled by the user'; break; case 'field_invalid_card_number': errorMessage = 'Missing or invalid creditcard number'; break; case 'field_invalid_card_exp_year': errorMessage = 'Missing or invalid expiry year'; break; case 'field_invalid_card_exp_month': errorMessage = 'Missing or invalid expiry month'; break; case 'field_invalid_card_exp': errorMessage = 'Card is no longer valid or has expired'; break; case 'field_invalid_card_cvc': errorMessage = 'Invalid checking number'; break; case 'field_invalid_card_holder': errorMessage = 'Invalid cardholder'; break; case 'field_invalid_amount_int': errorMessage = 'Invalid or missing amount for 3-D Secure'; break; case 'field_invalid_amount': errorMessage = 'Invalid or missing amount for 3-D Secure deprecated, see blog post'; break; case 'field_invalid_currency': errorMessage = 'Invalid or missing currency code for 3-D Secure'; break; case 'field_invalid_account_number': errorMessage = 'Missing or invalid bank account number'; break; case 'field_invalid_account_holder': errorMessage = 'Missing or invalid bank account holder'; break; case 'field_invalid_bank_code': errorMessage = 'Missing or invalid bank code '; break; default: errorMessage = error.apierror; } el.after("<span class='error'><br />"+errorMessage+"</span>"); } else { frm.find("input[name=paymill_token]").val(result.token); frm.submit(); } }); frm.find("input[type=submit]").prop('disabled', 'disabled'); return false; }); }); CUT ); return $form; }
public function createDeclarationForm() { $form = new Am_Form('dd-declaretion'); $form->addProlog('<h2>Declaration</h2>'); $form->addAdvCheckbox('i_agree')->setLabel('I wish to start Direct Debit')->addRule('required'); $form->addSaveButton('Proceed'); $form->addEpilog(<<<CUT <h2>Information</h2> <p>All the normal Direct Debit safeguards and guarantees apply. No changes in the amount, date, frequency to be debited can be made without notifying you at least five (5) working days in advance of your account being debited. In the event of error, you are entitled to an immediate refund from your Bank or Building Society. You have the right to cancel a Direct Debit Instruction at any time simply by writing to your Bank or Building Society, with a copy to us.</p> CUT ); $form->addHidden(Am_Controller::ACTION_KEY)->setValue($this->getRequest()->getActionName()); $form->addHidden('id')->setValue($this->getFiltered('id')); return $form; }