public function getData(Order $order) { $data = array(); $gateway = Checkout::get($order)->getSelectedPaymentMethod(); //provide valid dummy credit card data if ($gateway === "Dummy") { $data = array_merge(array('name' => 'Joe Bloggs', 'number' => '4242424242424242', 'cvv' => 123), $data); } return $data; }
/** * @param Order $order * * @return \Omnipay\Common\AbstractGateway|\Omnipay\Braintree\Gateway */ protected function getGateway($order) { if (!isset($this->gateway)) { $tempPayment = new Payment(['Gateway' => Checkout::get($order)->getSelectedPaymentMethod(false)]); $service = PurchaseService::create($tempPayment); $this->gateway = $service->oGateway(); $this->isBraintree = $this->gateway instanceof \Omnipay\Braintree\Gateway; } return $this->gateway; }
/** * Behaviour can be overwritten by creating a processPaymentResponse method * on the controller owning this form. It takes a Symfony\Component\HttpFoundation\Response argument, * and expects an SS_HTTPResponse in return. */ public function submitpayment($data, $form) { $data = $form->getData(); if ($this->getSuccessLink()) { $data['returnUrl'] = $this->getSuccessLink(); } $data['cancelUrl'] = $this->getFailureLink() ? $this->getFailureLink() : $this->controller->Link(); $order = $this->config->getOrder(); //final recalculation, before making payment $order->calculate(); //handle cases where order total is 0. Note that the order will appear //as "paid", but without a Payment record attached. if ($order->GrandTotal() == 0 && Order::config()->allow_zero_order_total) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } return $this->controller->redirect($this->getSuccessLink()); } //try to place order before payment, if configured if (Order::config()->place_before_payment) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } $data['cancelUrl'] = $this->orderProcessor->getReturnUrl(); } $paymentResponse = $this->orderProcessor->makePayment(Checkout::get($order)->getSelectedPaymentMethod(false), $data); $response = null; if ($paymentResponse) { if ($this->controller->hasMethod('processPaymentResponse')) { $response = $this->controller->processPaymentResponse($paymentResponse, $form); } else { if ($paymentResponse->isRedirect() || $paymentResponse->isSuccessful()) { $response = $paymentResponse->redirect(); } else { $form->sessionMessage($paymentResponse->getMessage(), 'bad'); $response = $this->controller->redirectBack(); } } } else { $form->sessionMessage($this->orderProcessor->getError(), 'bad'); $response = $this->controller->redirectBack(); } return $response; }
public function setData(Order $order, array $data) { if (isset($data['PaymentMethod'])) { Checkout::get($order)->setPaymentMethod($data['PaymentMethod']); } }
public function SelectedPaymentMethod() { return Checkout::get($this->owner->Cart())->getSelectedPaymentMethod(true); }
/** * Behaviour can be overwritten by creating a processPaymentResponse method * on the controller owning this form. It takes a Symfony\Component\HttpFoundation\Response argument, * and expects an SS_HTTPResponse in return. */ public function submitpayment($data, $form) { $data = $form->getData(); $cancelUrl = $this->getFailureLink() ? $this->getFailureLink() : $this->controller->Link(); $order = $this->config->getOrder(); // final recalculation, before making payment $order->calculate(); // handle cases where order total is 0. Note that the order will appear // as "paid", but without a Payment record attached. if ($order->GrandTotal() == 0 && Order::config()->allow_zero_order_total) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } return $this->controller->redirect($this->getSuccessLink()); } // try to place order before payment, if configured if (Order::config()->place_before_payment) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } $cancelUrl = $this->orderProcessor->getReturnUrl(); } // if we got here from checkoutSubmit and there's a namespaced OnsitePaymentCheckoutComponent // in there, we need to strip the inputs down to only the checkout component. $components = $this->config->getComponents(); if ($components->first() instanceof CheckoutComponent_Namespaced) { foreach ($components as $component) { if ($component->Proxy() instanceof OnsitePaymentCheckoutComponent) { $data = array_merge($data, $component->unnamespaceData($data)); } } } // This is where the payment is actually attempted $paymentResponse = $this->orderProcessor->makePayment(Checkout::get($order)->getSelectedPaymentMethod(false), $data, $this->getSuccessLink(), $cancelUrl); $response = null; if ($this->controller->hasMethod('processPaymentResponse')) { $response = $this->controller->processPaymentResponse($paymentResponse, $form); } else { if ($paymentResponse && !$paymentResponse->isError()) { $response = $paymentResponse->redirectOrRespond(); } else { $form->sessionMessage($this->orderProcessor->getError(), 'bad'); $response = $this->controller->redirectBack(); } } return $response; }
public function testSummary() { $this->checkout->summary(); $form = $this->checkout->ConfirmationForm(); $data = array('Notes' => 'Leave it around the back', 'ReadTermsAndConditions' => 1); $member = $this->objFromFixture("Member", "joebloggs"); $member->logIn(); //log in member before processing Checkout::get($this->cart)->setPaymentMethod("Dummy"); //a selected payment method is required $form->loadDataFrom($data); $this->assertTrue($form->validate(), "Checkout data is valid"); $response = $this->post('/checkout/ConfirmationForm', $data); $this->assertEquals('Cart', $this->cart->Status, "Order is still in cart"); $order = Order::get()->byID($this->cart->ID); $this->assertEquals("Leave it around the back", $order->Notes); //redirect to make payment $this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(Director::baseURL() . "checkout/payment", $response->getHeader('Location')); }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Checkout a guest * * calendar * * @since 2004-01-22 * @author Christian Ehret <*****@*****.**> */ $smartyType = "www"; include_once "../includes/default.inc.php"; $auth->is_authenticated(); include_once 'checkoutclass.inc.php'; if ($request->GetVar('list', 'get') == 'true') { $smarty->assign("tpl_title", "Anwesenheitsliste"); $smarty->assign('tpl_nav', 'lists'); $smarty->assign('tpl_subnav', 'checkout'); $smarty->assign('tpl_checkout', 'false'); } else { $smarty->assign("tpl_title", "Checkout"); $smarty->assign('tpl_nav', 'calendar'); $smarty->assign('tpl_subnav', 'checkout'); $smarty->assign('tpl_checkout', 'true'); } $checkout = new Checkout(); $smarty->assign('tpl_guests', $checkout->get()); $smarty->display('checkoutlist.tpl');