public function getVisibleFormFields(Customweb_Payment_Authorization_IOrderContext $orderContext, $aliasTransaction, $failedTransaction, $isMoto = false) { $formBuilder = new Customweb_Payment_Authorization_Method_CreditCard_ElementBuilder(); // Set field names $formBuilder->setCardHolderFieldName(self::FORM_KEY_OWNER_NAME)->setCardNumberFieldName(self::FORM_KEY_CARD_NUMBER)->setCvcFieldName(self::FORM_KEY_CARD_CVC)->setExpiryMonthFieldName(self::FORM_KEY_CARD_EXPIRY_MONTH)->setExpiryYearFieldName(self::FORM_KEY_CARD_EXPIRY_YEAR)->setExpiryYearNumberOfDigits(2); // Handle brand selection if (strtolower($this->getPaymentMethodName()) == 'creditcard') { $brands = $this->getPaymentMethodConfigurationValue('credit_card_brands'); $formBuilder->setCardHandlerByBrandInformationMap($this->getPaymentInformationMap(), $brands, 'id')->setAutoBrandSelectionActive(true); } else { $formBuilder->setFixedBrand(true)->setSelectedBrand($this->getPaymentMethodName())->setCardHandlerByBrandInformationMap($this->getPaymentInformationMap(), $this->getPaymentMethodName(), 'id'); } $formBuilder->setCardHolderName($orderContext->getBillingFirstName() . ' ' . $orderContext->getBillingLastName()); if ($aliasTransaction !== null && $aliasTransaction !== 'new' && $aliasTransaction instanceof Customweb_Saferpay_Authorization_Transaction) { $formBuilder->setSelectedExpiryMonth($aliasTransaction->getCardExpiryMonth()); $formBuilder->setSelectedExpiryYear($aliasTransaction->getCardExpiryYear()); $params = $aliasTransaction->getAuthorizationParameters(); $formBuilder->setMaskedCreditCardNumber($params['PAN']); $formBuilder->setCardHolderName($aliasTransaction->getOwnerName()); } if ($isMoto) { $formBuilder->setCvcFieldName(null); } return $formBuilder->build(); }
/** * Creates a key based on both addresses found in the orderContext * * @param Customweb_Payment_Authorization_IOrderContext $orderContext * @param array $additionalData Other identifiers to be added to the generated key (e.g. amount, payment type etc) * @return string */ public static function generateAddressKey(Customweb_Payment_Authorization_IOrderContext $orderContext, $additionalData = array()) { $billing = $orderContext->getBillingAddress(); $shipping = $orderContext->getShippingAddress(); $addressParts = array_merge(self::addressPartsToArray($billing), self::addressPartsToArray($shipping), $additionalData); $addressString = Customweb_Core_String::_(implode($addressParts))->toLowerCase()->toString(); return substr(hash('SHA512', $addressString), 0, 160); }
/** * This method validates if the given $orderContext and $paymentContext are valid to be * processed with this payment method. * * Subclasses may override this method, but they should call the parent method. * * @param Customweb_Payment_Authorization_IOrderContext $orderContext * @param Customweb_Payment_Authorization_IPaymentCustomerContext $paymentContext * @throws Exception In case something is not valid. */ public function preValidate(Customweb_Payment_Authorization_IOrderContext $orderContext, Customweb_Payment_Authorization_IPaymentCustomerContext $paymentContext) { if (!$this->isCountrySupported($orderContext->getBillingCountryIsoCode())) { throw new Exception(Customweb_I18n_Translation::__("The payment method !paymentMethodName is not available in your country ('!country').", array('!paymentMethodName' => $this->getPaymentMethodDisplayName(), '!country' => $orderContext->getBillingCountryIsoCode()))); } if (!$this->isCurrencySupported($orderContext->getCurrencyCode())) { throw new Exception(Customweb_I18n_Translation::__("The payment method !paymentMethodName does not support the currency '!currency'.", array('!paymentMethodName' => $this->getPaymentMethodDisplayName(), '!currency' => $orderContext->getCurrencyCode()))); } return true; }
private function getMandateElements(Customweb_Payment_Authorization_IOrderContext $orderContext) { $customer = $orderContext->getBillingAddress()->getFirstName() . ' ' . $orderContext->getBillingAddress()->getLastName(); $mandateId = Customweb_Payment_Authorization_Method_Sepa_Mandate::generateMandateId(self::$MANDATE_ID_SCHEMA); $mandateIdControl = new Customweb_Form_Control_HiddenInput('MANDATEID', $mandateId); $mandateIdElement = new Customweb_Form_HiddenElement($mandateIdControl); $mandateTextControl = new Customweb_Form_Control_Html('mandate_text', $this->getMandateText($mandateId, $customer)); $mandateTextElement = new Customweb_Form_Element(Customweb_I18n_Translation::__('Mandate text'), $mandateTextControl); $mandateTextElement->setRequired(false); return array($mandateIdElement, $mandateTextElement); }
/** * Fetches a list of transaction which can be used as alias transactions for the given order context. * * @param Customweb_Payment_Authorization_IOrderContext $orderContext * @return Customweb_Payment_Entity_AbstractTransaction[] */ public function getAliasTransactions(Customweb_Payment_Authorization_IOrderContext $orderContext) { $customerId = $orderContext->getCustomerId(); if ($customerId === null) { return array(); } $transactions = $this->manager->search($this->transactionClassName, 'customerId = >customerId AND paymentMachineName = >paymentMethodName AND aliasActive = "y" AND aliasForDisplay IS NOT NULL AND aliasForDisplay != ""', 'createdOn DESC', array('>customerId' => $customerId, '>paymentMethodName' => $orderContext->getPaymentMethod()->getPaymentMethodName())); $result = array(); foreach ($transactions as $transaction) { /* @var $transaction Customweb_Payment_Entity_AbstractTransaction */ if (!isset($result[$transaction->getAliasForDisplay()])) { $result[$transaction->getAliasForDisplay()] = $transaction; } } return $result; }
/** * This method tries to instanciated an adapter for the given authorization method. If the authorization method * is not supported for the given context the next one in the stack is tried. * * @param string $currentMethod * @param array $supportedMethod * @param Customweb_Payment_Authorization_IOrderContext $context * @throws Exception In case no adapter matches the given parameters. */ private function getAdapterByOrderContextInner($currentMethod, array $supportedMethod, Customweb_Payment_Authorization_IOrderContext $context) { if (count($supportedMethod) <= 0) { throw new Exception(Customweb_I18n_Translation::__("No authorization method found for payment method !method.", array('!method' => $context->getPaymentMethod()->getPaymentMethodName()))); } $adapter = $this->getAuthorizationAdapterByName($currentMethod); if ($adapter->isAuthorizationMethodSupported($context)) { return $adapter; } else { $applicableMethods = array(); foreach ($supportedMethod as $methodName) { if ($methodName == $currentMethod) { break; } $applicableMethods[] = $methodName; } return $this->getAdapterByOrderContextInner(end($applicableMethods), $applicableMethods, $context); } }
public function getVisibleFormFields(Customweb_Payment_Authorization_IOrderContext $orderContext, $aliasTransaction, $failedTransaction, $isMoto = false) { $elements = array(); $owner = $this->getOrderContext()->getBillingFirstName() . ' ' . $this->getOrderContext()->getBillingLastName(); if ($orderContext->getBillingCompanyName() == null) { $elements[] = Customweb_Saferpay_ElementFactory::getCompanyElement('COMPANY'); } if ($this->getGender($orderContext->getBillingGender(), $orderContext->getBillingCompanyName()) == null) { $elements[] = Customweb_Saferpay_ElementFactory::getGenderElement('GENDER'); } if ($orderContext->getBillingDateOfBirth() == null) { $dobElement = Customweb_Saferpay_ElementFactory::getDateOfBirthElement('dob-day', 'dob-month', 'dob-year'); $elements[] = $dobElement; } if ($this->getGender($orderContext->getShippingGender(), "") == null) { $elements[] = Customweb_Saferpay_ElementFactory::getGenderElement('DELIVERY_GENDER'); } $elements[] = Customweb_Form_ElementFactory::getAccountOwnerNameElement('NAME', $owner); $elements[] = Customweb_Form_ElementFactory::getAccountNumberElement('ACCOUNTNUMBER'); $elements[] = Customweb_Form_ElementFactory::getBankCodeElement('BANK_CODE_NUMBER'); $elements[] = $this->getGeneralTermsElement("generalTerms"); return $elements; }
/** * This method throws an exception in case the shipping and billing address do not match. * * @param Customweb_Payment_Authorization_IOrderContext $orderContext * @throws Exception */ protected function checkAddresses(Customweb_Payment_Authorization_IOrderContext $orderContext) { if ($orderContext->getBillingCity() != $orderContext->getShippingCity()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } if ($orderContext->getBillingPostCode() != $orderContext->getShippingPostCode()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } if ($orderContext->getBillingStreet() != $orderContext->getShippingStreet()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } if ($orderContext->getBillingFirstName() != $orderContext->getShippingFirstName()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } if ($orderContext->getBillingLastName() != $orderContext->getShippingLastName()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } if ($orderContext->getBillingCountryIsoCode() != $orderContext->getShippingCountryIsoCode()) { throw new Exception(Customweb_I18n_Translation::__("The billing and shipping address do not match.")); } return true; }
public static function getWrapper(Customweb_Payment_Authorization_IOrderContext $orderContext) { $wrapper = self::getWrapperFromPaymentMethod($orderContext->getPaymentMethod()); $wrapper->setOrderContext($orderContext); return $wrapper; }
public function getVisibleFormFields(Customweb_Payment_Authorization_IOrderContext $orderContext, $aliasTransaction, $failedTransaction, $paymentCustomerContext) { $adapter = $this->getAdapterInstanceByPaymentMethod($orderContext->getPaymentMethod()); return $adapter->getVisibleFormFields($orderContext, $aliasTransaction, $failedTransaction, $paymentCustomerContext); }
public function addSpecificPaymentPageParameters(Customweb_Payment_Authorization_IOrderContext $orderContext, array $parameters) { $this->orderContext = $orderContext; $this->addIfValueNotNull($parameters, 'COMPANY', Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCompanyName())); $this->addIfValueNotNull($parameters, 'LEGALFORM', $this->guessLegalForm()); $this->addIfValueNotNull($parameters, 'GENDER', $this->getGender($orderContext->getBillingGender(), $orderContext->getBillingCompanyName())); $parameters['FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingFirstName()); $parameters['LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingLastName()); $parameters['STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingStreet()); $parameters['ZIP'] = $orderContext->getBillingPostCode(); $parameters['CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCity()); $parameters['COUNTRY'] = $orderContext->getBillingCountryIsoCode(); $parameters['EMAIL'] = $orderContext->getCustomerEMailAddress(); $this->addIfValueNotNull($parameters, 'PHONE', $orderContext->getBillingPhoneNumber()); if ($orderContext->getBillingDateOfBirth() != null) { $this->addIfValueNotNull($parameters, 'DATEOFBIRTH', $orderContext->getBillingDateOfBirth()->format('Ymd')); } $this->addIfValueNotNull($parameters, 'DELIVERY_GENDER', $this->getGender($orderContext->getShippingGender(), "")); $parameters['DELIVERY_FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingFirstName()); $parameters['DELIVERY_LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingLastName()); $parameters['DELIVERY_STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingStreet()); $parameters['DELIVERY_ZIP'] = $orderContext->getShippingPostCode(); $parameters['DELIVERY_CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingCity()); $parameters['DELIVERY_COUNTRY'] = $orderContext->getShippingCountryIsoCode(); $this->addIfValueNotNull($parameters, 'DELIVERY_PHONE', $orderContext->getShippingPhoneNumber()); $parameters['LANGID'] = substr($orderContext->getLanguage(), 0, 2); //$parameters['IP'] = Customweb_Saferpay_Util::getClientIpAddress(); return $parameters; }
protected function getShippingAddressHash(Customweb_Payment_Authorization_IOrderContext $orderContext) { $addressString = $orderContext->getShippingFirstName() . '|' . $orderContext->getShippingLastName() . '|' . $orderContext->getShippingStreet() . '|' . $orderContext->getShippingCity() . '|' . $orderContext->getShippingCountryIsoCode() . '|' . $orderContext->getShippingState(); return hash('sha256', $addressString); }
/** * This method takes the two order contexts and compare their shipping addresses. * The method returns true, when they equal. * * @param Customweb_Payment_Authorization_IOrderContext $orderContext1 * @param Customweb_Payment_Authorization_IOrderContext $orderContext2 * @return boolean */ public static function compareShippingAddresses(Customweb_Payment_Authorization_IOrderContext $orderContext1, Customweb_Payment_Authorization_IOrderContext $orderContext2) { return self::compareAddresses($orderContext1->getShippingAddress(), $orderContext2->getShippingAddress()); }