public function testClassConfig() { $processor = PaymentFactory::factory('DummyMerchantHosted'); $this->assertEquals(get_class($processor), 'DummyProcessor_MerchantHosted'); $this->assertEquals(get_class($processor->gateway), 'DummyGateway_MerchantHosted'); $this->assertEquals(get_class($processor->payment), 'Payment'); }
public function testClassConfig() { $controller = PaymentFactory::factory('DummyGatewayHosted'); $this->assertEquals(get_class($controller), 'DummyProcessor_GatewayHosted'); $this->assertEquals(get_class($controller->gateway), 'DummyGateway_GatewayHosted'); $this->assertEquals(get_class($controller->payment), 'Payment'); }
public function testClassConfig() { $processor = PaymentFactory::factory('Credit'); $this->assertEquals(get_class($processor), 'CreditProcessor'); $this->assertEquals(get_class($processor->gateway), 'CreditGateway'); $this->assertEquals(get_class($processor->payment), 'Payment'); }
public function setUp() { parent::setUp(); $paymentMethods = array('dev' => array('DummyMerchantHosted')); Config::inst()->remove('PaymentProcessor', 'supported_methods'); Config::inst()->update('PaymentProcessor', 'supported_methods', $paymentMethods); Config::inst()->remove('PaymentGateway', 'environment'); Config::inst()->update('PaymentGateway', 'environment', 'dev'); $this->processor = PaymentFactory::factory('DummyMerchantHosted'); }
function setUp() { parent::setUp(); $paymentMethods = array('test' => array('PayPalDirect')); Config::inst()->remove('PaymentProcessor', 'supported_methods'); Config::inst()->update('PaymentProcessor', 'supported_methods', $paymentMethods); Config::inst()->remove('PaymentGateway', 'environment'); Config::inst()->update('PaymentGateway', 'environment', 'test'); $this->processor = PaymentFactory::factory('PayPalDirect'); $this->data = array('Amount' => '10', 'Currency' => 'USD', 'CreditCard' => new CreditCard(array('firstName' => 'Ryan', 'lastName' => 'Dao', 'type' => 'master', 'month' => '11', 'year' => '2016', 'number' => '4381258770269608'))); }
function setUp() { parent::setUp(); $paymentMethods = array('test' => array('PayPalExpress')); Config::inst()->remove('PaymentProcessor', 'supported_methods'); Config::inst()->update('PaymentProcessor', 'supported_methods', $paymentMethods); Config::inst()->remove('PaymentGateway', 'environment'); Config::inst()->update('PaymentGateway', 'environment', 'test'); $this->processor = PaymentFactory::factory('PayPalExpress'); $this->data = array('Amount' => '10', 'Currency' => 'USD'); }
function setUp() { parent::setUp(); Config::inst()->remove('PaymentGateway', 'environment'); Config::inst()->update('PaymentGateway', 'environment', 'test'); // $paymentMethods = array('test' => array('PaymentExpressPxPay')); Config::inst()->remove('PaymentProcessor', 'supported_methods'); Config::inst()->update('PaymentProcessor', 'supported_methods', array('test' => array('PaymentExpressPxPay'))); $gatewayConfig = array('authentication' => array('user_id' => 'mock_user_id', 'key' => 'mock_key')); Config::inst()->remove('PaymentExpressGateway_PxPay', 'test'); Config::inst()->update('PaymentExpressGateway_PxPay', 'test', $gatewayConfig); $this->processor = PaymentFactory::factory('PaymentExpressPxPay'); $this->data = array('Amount' => '10', 'Currency' => 'USD'); }
public function processOrder($data, Form $form) { try { $processor = PaymentFactory::factory($this->paymentMethod); } catch (Exception $e) { return array('Content' => $e->getHTTPResponse()); } try { $processor->setRedirectURL($this->link() . 'complete'); $processor->capture($data); } catch (Exception $e) { $result = $processor->gateway->getValidationResult(); $payment = $processor->payment; return array('Content' => $this->customise(array('ExceptionMessage' => $e->getHTTPResponse(), 'ValidationMessage' => $result->getHTTPResponse(), 'OrderForm' => $this->OrderForm(), 'Payment' => $payment))->renderWith('PaymentTestPage')); } }
/** * Process order */ function processOrder($data, $form) { $paymentMethod = $data['PaymentMethod']; try { $paymentProcessor = PaymentFactory::factory($paymentMethod); } catch (Exception $e) { return array('Content' => $e->getMessage()); } try { $paymentProcessor->setRedirectURL($this->link() . 'completed'); $paymentProcessor->capture($data); } catch (Exception $e) { //This is where we catch gateway validation or gateway unreachable errors $result = $paymentProcessor->gateway->getValidationResult(); $payment = $paymentProcessor->payment; return array('Content' => $this->customise(array('ExceptionMessage' => $e->getMessage(), 'ValidationMessage' => $result->message(), 'OrderForm' => $this->OrderForm(), 'Payment' => $payment))->renderWith('PaymentTestPage')); } }
public function processOrder($data) { $paymentMethod = $data['PaymentMethod']; try { $paymentProcessor = PaymentFactory::factory($paymentMethod); } catch (Exception $e) { return array('Content' => $e->getMessage()); } try { $paymentProcessor->setRedirectURL($this->link() . "?name={$this->myEventName}&accepted=1"); $paymentProcessor->capture($data); } catch (Exception $e) { //This is where we catch gateway validation or gateway unreachable errors $result = $paymentProcessor->gateway->getValidationResult(); $payment = $paymentProcessor->payment; return array('Content' => $this->customise(array('ExceptionMessage' => $e->getMessage(), 'Payment' => $payment))); } }
public function validateStep($data, $form) { Session::set("FormInfo.{$form->FormName()}.data", $form->getData()); $payment = $data['PaymentMethod']; $tickets = $this->getForm()->getSavedStepByClass('EventRegisterTicketsStep'); $total = $tickets->getTotal(); $registration = $this->form->getSession()->getRegistration(); $data['Currency'] = $total->Currency; $data['Amount'] = $total->Amount; $processor = PaymentFactory::factory($payment); try { $link = $registration->Link(); $link = $this->Link(); // Set the url to redirect to after the payment is completed, e.g. $processor->setRedirectURL(Director::absoluteURL($link)); // Process the payment $processor->capture($data); } catch (Exception $e) { // Most likely due to connection cannot be extablished or validation fails return false; } $result = $processor->gateway->getValidationResult(); $controller = Controller::curr(); /* @var $controller Controller */ if ($controller->redirectedTo()) { return true; } if (!$result->valid()) { $form->sessionMessage($result->message(), 'required'); return false; } $this->checkPayment($registration); // Write an empty registration object so we have an ID to reference the // payment against. This will be populated in the form's finish() method. $registration->Status = 'Valid'; $registration->write(); Session::set("EventRegistration.{$registration->ID}.message", strip_tags($payment->Message)); return true; }
public function process($data, $form) { //Check payment type try { $paymentMethod = $data['PaymentMethod']; $paymentProcessor = PaymentFactory::factory($paymentMethod); } catch (Exception $e) { Debug::friendlyError(403, _t('CheckoutPage.NOT_VALID_METHOD', "Sorry, that is not a valid payment method."), _t('CheckoutPage.TRY_AGAIN', "Please go back and try again.")); return; } $member = Customer::currentUser(); $orderID = Session::get('Repay.OrderID'); if ($orderID) { $order = DataObject::get_by_id('Order', $orderID); } Session::clear('Repay.OrderID'); $order->onBeforePayment(); try { $paymentData = array('Amount' => number_format($order->TotalOutstanding()->getAmount(), 2, '.', ''), 'Currency' => $order->TotalOutstanding()->getCurrency(), 'Reference' => $order->ID); $paymentProcessor->payment->OrderID = $order->ID; $paymentProcessor->payment->PaidByID = $member->ID; $paymentProcessor->setRedirectURL($order->Link()); $paymentProcessor->capture($paymentData); } catch (Exception $e) { //This is where we catch gateway validation or gateway unreachable errors $result = $paymentProcessor->gateway->getValidationResult(); $payment = $paymentProcessor->payment; //TODO: Need to get errors and save for display on order page SS_Log::log(new Exception(print_r($result->message(), true)), SS_Log::NOTICE); SS_Log::log(new Exception(print_r($e->getMessage(), true)), SS_Log::NOTICE); $this->controller->redirect($order->Link()); } }
public function process($data, $form) { $this->extend('onBeforeProcess', $data); //Check payment type try { $paymentMethod = Convert::raw2sql($data['PaymentMethod']); $paymentProcessor = PaymentFactory::factory($paymentMethod); } catch (Exception $e) { Debug::friendlyError(403, _t('CheckoutPage.NOT_VALID_METHOD', "Sorry, that is not a valid payment method."), _t('CheckoutPage.TRY_AGAIN', "Please go back and try again.")); return; } //Save or create a new customer/member $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer'); if (!$member->exists()) { $existingCustomer = Customer::get()->filter('Email', $data['Email']); if ($existingCustomer && $existingCustomer->exists()) { $form->sessionMessage(_t('CheckoutPage.MEMBER_ALREADY_EXISTS', 'Sorry, a member already exists with that email address. If this is your email address, please log in first before placing your order.'), 'bad'); $this->controller->redirectBack(); return false; } $member = Customer::create(); $form->saveInto($member); $member->write(); $member->addToGroupByCode('customers'); $member->logIn(); } //Save the order $order = Cart::get_current_order(); $items = $order->Items(); $form->saveInto($order); $order->MemberID = $member->ID; $order->Status = Order::STATUS_PENDING; $order->OrderedOn = SS_Datetime::now()->getValue(); $order->write(); //Saving an update on the order if ($notes = $data['Notes']) { $update = new Order_Update(); $update->Note = $notes; $update->Visible = true; $update->OrderID = $order->ID; $update->MemberID = $member->ID; $update->write(); } //Add modifiers to order $order->updateModifications($data)->write(); Session::clear('Cart.OrderID'); $order->onBeforePayment(); try { $shopConfig = ShopConfig::current_shop_config(); $precision = $shopConfig->BaseCurrencyPrecision; $paymentData = array('Amount' => number_format($order->Total()->getAmount(), $precision, '.', ''), 'Currency' => $order->Total()->getCurrency(), 'Reference' => $order->ID); $paymentProcessor->payment->OrderID = $order->ID; $paymentProcessor->payment->PaidByID = $member->ID; $paymentProcessor->setRedirectURL($order->Link()); $paymentProcessor->capture($paymentData); } catch (Exception $e) { //This is where we catch gateway validation or gateway unreachable errors $result = $paymentProcessor->gateway->getValidationResult(); $payment = $paymentProcessor->payment; //TODO: Need to get errors and save for display on order page SS_Log::log(new Exception(print_r($result->message(), true)), SS_Log::NOTICE); SS_Log::log(new Exception(print_r($e->getMessage(), true)), SS_Log::NOTICE); $this->controller->redirect($order->Link()); } }