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 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('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 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('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(); $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(); 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 complete($request) { // Reconstruct the payment object $this->payment = Payment::get()->byID($request->param('OtherID')); // Save the payer ID for good measure $this->payment->PayerID = $request->getVar('PayerID'); $this->payment->write(); // Reconstruct the gateway object $methodName = $request->param('ID'); $this->gateway = PaymentFactory::get_gateway($methodName); // Confirm the payment $data = array('PayerID' => $request->getVar('PayerID'), 'Token' => $request->getVar('token'), 'Amount' => $this->payment->Amount->Amount, 'Currency' => $this->payment->Amount->Currency); $result = $this->gateway->confirm($data); $this->payment->updateStatus($result); // Do redirection $this->doRedirect(); return; }
/** * 发货 * */ public function send_goods() { if ($this->isAjax()) { $id = intval($_REQUEST['id']); $record = M('payment')->where("id='{$id}'")->find(); if ($record['status'] == 104 || $record['status'] == 105) { $this->ajaxReturn('', '该交易已发货或已完成', 0); } import('@.Com.payment.PaymentFactory'); $payment = PaymentFactory::getPayment('AlipayWarrant'); $response = $payment->send_goods(array('trade_no' => $record['trade_no'])); if ($response) { M('payment')->where("id='{$id}'")->save(array('status' => 105)); $this->ajaxReturn('', '操作成功', 1); } else { $this->ajaxReturn('', '操作失败', 0); } } }
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) { $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()); } }
private function _pay_notify_alipay_warrant() { import('@.Com.payment.PaymentFactory'); $payment = PaymentFactory::getPayment('AlipayWarrant'); $result = $payment->verifyNotify(); if ($result !== false) { $result['trade_status'] = trim($result['trade_status']); if ($result['trade_status'] == 'WAIT_BUYER_PAY' || $result['trade_status'] == 'WAIT_SELLER_SEND_GOODS' || $result['trade_status'] == 'WAIT_BUYER_CONFIRM_GOODS' || $result['trade_status'] == 'TRADE_FINISHED') { $record = M('payment')->where("out_trade_no='{$result['out_trade_no']}'")->find(); if ($record['status'] == 104) { exit('success'); } if ($record && $record['amount'] == $result['total_fee']) { $status = 102; //等待买家付款 if ($result['trade_status'] == 'WAIT_BUYER_PAY') { $status = 103; } else { if ($result['trade_status'] == 'WAIT_SELLER_SEND_GOODS') { //自动发货 $response = $payment->send_goods(array('trade_no' => $result['trade_no'])); if ($response) { $status = 105; } else { $status = 102; } } else { if ($result['trade_status'] == 'WAIT_BUYER_CONFIRM_GOODS') { $status = 105; } else { if ($result['trade_status'] == 'TRADE_FINISHED') { if ($record && $record['amount'] == $result['total_fee']) { //记录日志 Consume::increase($record['user_id'], $result['total_fee'], Consume::TYPE_MONEY); $status = 104; } else { $status = $record['status']; } } } } } M('payment')->where("out_trade_no='{$result['out_trade_no']}'")->save(array('status' => $status, 'trade_no' => $result['trade_no'])); exit('success'); } else { exit('fail'); } } else { exit('fail'); } } else { exit('fail'); } }
/** * Process request from the external gateway, this action is usually triggered if the payment was cancelled * and the user was redirected to the cancelURL. * * @param SS_HTTPResponse $request */ public function cancel($request) { // Reconstruct the payment object $this->payment = Payment::get()->byID($request->param('OtherID')); // Reconstruct the gateway object $methodName = $request->param('ID'); $this->gateway = PaymentFactory::get_gateway($methodName); // The payment result was a failure $this->payment->updateStatus(new PaymentGateway_Failure()); // Do redirection $this->doRedirect(); }
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()); } }
require_once "Database.php"; require_once "SlowTemplate.php"; require_once "WebUtility.php"; require_once "Payment.php"; require_once "PaymentFactory.php"; $slow = new SlowTemplate('template'); $slow->setTemplateFile('home2.tpl'); session_start(); ////////////////////////////////////////////////////////////////////////////// // handle the submission if ($_SERVER["REQUEST_METHOD"] == 'POST') { if ($_POST['__VIEWSTATE'] == $_SESSION['VIEWSTATE']) { } } ////////////////////////////////////////////////////////////////////////////// // display the page $view = WebUtility::viewstate(1476); $_SESSION['VIEWSTATE'] = $view; // Tariff's $tariffs = array('MFI Tariff 4', 'Unkown'); // page size $pagesizes = array(20, 50, 100, 500); // Search results $results = PaymentFactory::factoryAll(); foreach ($results as $result) { $slow->assign(array("RECEIPT" => $result->getReciept(), "TIME" => date("Y-m-d H:i:s", $result->getTime()), "DESCRIPTION" => "Payment received from " . $result->getPhonenumber() . " - " . $result->getName() . " Acc. " . $result->getAccount(), "STATUS" => "Completed", "AMOUNT" => number_format($result->getAmount(), 2, '.', ''), "BALANCE" => number_format($result->getPostBalance(), 2, '.', ''), "HASH" => "b142222a-59ab-2ef6-8e52-a027ca4edb21")); $slow->parse("Result"); } $slow->assign(array("VIEWSTATE" => $view, "ORGANISATION" => "MpesaPi", "USERNAME" => "Test Testson", "LOGIN_TIME" => date("Y-m-d H:i:s"), "LAST_LOGIN_TIME" => date("Y-m-d H:i:s"), "ACCOUNT_NUMBER" => '32943321-11', "TARIFF" => $tariffs[1], "SEARCH_FROM" => date("Y-m-d H:i:s"), "SEARCH_FROM_DAY" => date("Y-m-d"), "SEARCH_FROM_TIME" => "00:00", "SEARCH_UNTIL" => date("Y-m-d H:i:s"), "SEARCH_UNTIL_DAY" => date("Y-m-d"), "SEARCH_UNTIL_TIME" => "23:59", "PAGE_SIZE_INDEX" => "0", "PAGE_SIZE" => $pagesizes[0], "CHECKED_ALL" => 'checked="checked"', "CHECKED_DECLINED" => '', "CHECKED_CANCELLED" => '', "CHECKED_EXPIRED" => '', "CHECKED_PENDING" => '', "CHECKED_COMPLETED" => '', "BALANCE_UPDATED" => date("Y-m-d H:i:s"), "CURRENT_BALANCE" => " 0.00", "UNCLEARED_FUNDS" => " 0.00", "RESERVED_FUNDS" => " 0.00", "AVAILABLE_FUNDS" => " 0.00")); $slow->parse(); $slow->slowPrint();