Exemplo n.º 1
0
 function testSetGet()
 {
     $this->CI->load->model('payment');
     $payment = new Payment($this->DBI);
     $payment->set('method', Payment::DIRECT);
     $this->assertEqual($payment->get('method'), Payment::DIRECT, "Test set and get");
     $passed = false;
     try {
         $payment->set('method', 'kooky');
     } catch (Exception $error) {
         $this->pass('Method set typing secure');
         $passed = true;
     }
     if (!$passed) {
         $this->fail("Failed to catch invalid set");
     }
     $passed = false;
     try {
         $payment->set('amount', 'not numeric');
     } catch (Exception $error) {
         $this->pass('Amount set typing secure');
         $passed = true;
     }
     if (!$passed) {
         $this->fail("Failed to catch invalid amount set");
     }
 }
 /**
  * Accepts a list of ids in form of comma separated string via GET parameter. If any of these payments is no longer
  * pending, this method returns true, false otherwise.
  * @param $gridField
  * @param \SS_HTTPRequest|null $request
  * @return bool
  */
 public function handleCheckPaymentPending($gridField, \SS_HTTPRequest $request = null)
 {
     if (!$request) {
         return false;
     }
     $ids = preg_split('/[^\\d]+/', $request->getVar('ids'));
     return \Payment::get()->filter('ID', $ids)->exclude('Status', array('PendingVoid', 'PendingCapture', 'PendingRefund'))->count() > 0;
 }
 public function complete()
 {
     $paymentID = Session::get('PaymentID');
     $payment = Payment::get()->byID($paymentID);
     if ($payment && !in_array($payment->Status, array($payment::SUCCESS, $payment::PENDING))) {
         $payment->updateStatus(new PaymentGateway_Result($payment::FAILURE));
     }
     return array('Content' => $this->customise(array('Payment' => $payment))->renderWith('PaymentTestPage'));
 }
 public function testNotifyEndpoint()
 {
     $this->setMockHttpResponse('PaymentExpress/Mock/PxPayCompletePurchaseSuccess.txt');
     //mock the 'result' get variable into the current request
     $this->getHttpRequest()->query->replace(array('result' => 'abc123'));
     //mimic a redirect or request from offsite gateway
     $response = $this->get("paymentendpoint/UNIQUEHASH23q5123tqasdf/notify");
     //redirect works
     $this->assertNull($response->getHeader('Location'));
     $payment = Payment::get()->filter('Identifier', 'UNIQUEHASH23q5123tqasdf')->first();
     $this->assertDOSContains(array(array('ClassName' => 'PurchaseRequest'), array('ClassName' => 'PurchaseRedirectResponse'), array('ClassName' => 'CompletePurchaseRequest'), array('ClassName' => 'PurchasedResponse')), $payment->Messages());
 }
 public function testPaymentIncomplete()
 {
     $this->processor->capture($this->data);
     //Test redirect to the gateway
     $response = Controller::curr()->getResponse();
     $gatewayURL = $this->processor->gateway->gatewayURL;
     $queryString = http_build_query(array('Amount' => $this->data['Amount'], 'Currency' => $this->data['Currency'], 'ReturnURL' => $this->processor->gateway->returnURL));
     $this->assertEquals($response->getHeader('Location'), '/dummy/external/pay?' . $queryString);
     //Test payment completion after redirect from gateway
     $queryString = http_build_query(array('Status' => 'Incomplete', 'ErrorMessage' => 'Awaiting Payment Confirmation', 'ErrorCode' => '54321'));
     Director::test($this->processor->gateway->returnURL . "?{$queryString}");
     $payment = $payment = Payment::get()->byID($this->processor->payment->ID);
     $this->assertEquals($payment->Status, Payment::INCOMPLETE);
     $error = $payment->Errors()->first();
     $this->assertEquals($error->ErrorMessage, 'Awaiting Payment Confirmation');
     $this->assertEquals($error->ErrorCode, '54321');
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 public function testDelete()
 {
     Config::inst()->update('FlatTaxModifier', 'rate', 0.25);
     Config::inst()->update('Order', 'modifiers', array('FlatTaxModifier'));
     $order = Order::create();
     $shirt = $this->objFromFixture("Product", "tshirt");
     $mp3player = $this->objFromFixture("Product", "mp3player");
     $order->Items()->add($shirt->createItem(3));
     $order->Items()->add($mp3player->createItem(1));
     $order->write();
     $order->calculate();
     $statusLogId = OrderStatusLog::create(array('Title' => 'Test status log', 'OrderID' => $order->ID))->write();
     $paymentId = Payment::create(array('OrderID' => $order->ID))->init('Manual', 343.75, 'NZD')->write();
     $this->assertEquals(4, $order->Items()->Quantity());
     $this->assertEquals(1, $order->Modifiers()->count());
     $this->assertEquals(1, $order->OrderStatusLogs()->count());
     $this->assertEquals(1, $order->Payments()->count());
     $itemIds = Product_OrderItem::get()->filter('OrderID', $order->ID)->column('ID');
     $modifierIds = OrderModifier::get()->filter('OrderID', $order->ID)->column('ID');
     $order->delete();
     // Items should no longer be linked to order
     $this->assertEquals(0, $order->Items()->count());
     $this->assertEquals(0, $order->Modifiers()->count());
     $this->assertEquals(0, $order->OrderStatusLogs()->count());
     $this->assertEquals(0, $order->Payments()->count());
     // Ensure the order items have been deleted!
     $this->assertEquals(0, Product_OrderItem::get()->filter('ID', $itemIds)->count());
     $this->assertEquals(0, OrderModifier::get()->filter('ID', $modifierIds)->count());
     $this->assertEquals(0, OrderStatusLog::get()->filter('ID', $statusLogId)->count());
     // Keep the payment… it might be relevant for book keeping
     $this->assertEquals(1, Payment::get()->filter('ID', $paymentId)->count());
 }
 /**
  * Map shop data to omnipay fields
  *
  * @param array $customData Usually user submitted data.
  *
  * @return array
  */
 protected function getGatewayData($customData)
 {
     $shipping = $this->order->getShippingAddress();
     $billing = $this->order->getBillingAddress();
     $numPayments = Payment::get()->filter(array('OrderID' => $this->order->ID))->count() - 1;
     $transactionId = $this->order->Reference . ($numPayments > 0 ? "-{$numPayments}" : '');
     return array_merge($customData, array('transactionId' => $transactionId, 'firstName' => $this->order->FirstName, 'lastName' => $this->order->Surname, 'email' => $this->order->Email, 'company' => $this->order->Company, 'billingAddress1' => $billing->Address, 'billingAddress2' => $billing->AddressLine2, 'billingCity' => $billing->City, 'billingPostcode' => $billing->PostalCode, 'billingState' => $billing->State, 'billingCountry' => $billing->Country, 'billingPhone' => $billing->Phone, 'shippingAddress1' => $shipping->Address, 'shippingAddress2' => $shipping->AddressLine2, 'shippingCity' => $shipping->City, 'shippingPostcode' => $shipping->PostalCode, 'shippingState' => $shipping->State, 'shippingCountry' => $shipping->Country, 'shippingPhone' => $shipping->Phone));
 }
Exemplo n.º 9
0
 /**
  * Get partial payments that have this payment as initial payment.
  * The list will be sorted from newest to oldest
  * @return DataList|null
  */
 public function getPartialPayments()
 {
     if (!$this->isInDB()) {
         return null;
     }
     return Payment::get()->filter('InitialPaymentID', $this->ID)->sort(array('Created' => 'DESC', 'ID' => 'DESC'));
 }
Exemplo n.º 10
0
 /**
  * deleting a payment
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  */
 public function delPayment($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->paymentId) || !($payment = Payment::get($param->CallbackParameter->paymentId)) instanceof Payment) {
             throw new Exception('System Error: invalid payment provided!');
         }
         if (!isset($param->CallbackParameter->reason) || ($reason = trim($param->CallbackParameter->reason)) === '') {
             throw new Exception('The reason for the deletion is needed!');
         }
         $comments = 'A payment [Value: ' . StringUtilsAbstract::getCurrency($payment->getValue()) . ', Method: ' . $payment->getMethod()->getName() . '] is DELETED: ' . $reason;
         $payment->setActive(false)->addComment($comments, Comments::TYPE_ACCOUNTING)->save();
         $entityFor = $payment->getOrder() instanceof Order ? $payment->getOrder() : $payment->getCreditNote();
         if ($entityFor instanceof Order || $entityFor instanceof CreditNote) {
             $entityFor->addComment($comments, Comments::TYPE_ACCOUNTING);
         }
         $results['item'] = $payment->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
 /**
  * Map shop data to omnipay fields
  *
  * @param array $customData Usually user submitted data.
  *
  * @return array
  */
 protected function getGatewayData($customData)
 {
     $shipping = $this->order->getShippingAddress();
     $billing = $this->order->getBillingAddress();
     $numPayments = Payment::get()->where(array('"OrderID" = ?' => $this->order->ID))->count();
     $numPayments--;
     $transactionId = strtoupper(i18n::get_lang_from_locale(i18n::get_locale())) . $this->order->Reference . ($numPayments > 0 ? '-' . $numPayments : '');
     if (Director::isDev()) {
         $transactionId .= Member::currentUser() ? '-' . Member::currentUserID() : '';
     }
     return array_merge($customData, array('transactionId' => $transactionId, 'firstName' => $this->order->FirstName, 'lastName' => $this->order->Surname, 'email' => $this->order->Email, 'company' => $this->order->Company, 'billingAddress1' => $billing->Address, 'billingAddress2' => $billing->AddressLine2, 'billingCity' => $billing->City, 'billingPostcode' => $billing->PostalCode, 'billingState' => $billing->State, 'billingCountry' => $billing->Country, 'billingPhone' => $billing->Phone, 'shippingAddress1' => $shipping->Address, 'shippingAddress2' => $shipping->AddressLine2, 'shippingCity' => $shipping->City, 'shippingPostcode' => $shipping->PostalCode, 'shippingState' => $shipping->State, 'shippingCountry' => $shipping->Country, 'shippingPhone' => $shipping->Phone));
 }
 public function Payment()
 {
     return Payment::get()->byID($this->PaymentID);
 }
 public function testNonExistantGateway()
 {
     //exception when trying to run functions that require a gateway
     $payment = $this->payment;
     $service = PurchaseService::create($payment->init("PxPayGateway", 100, "NZD"))->setReturnUrl("complete");
     $this->setExpectedException("RuntimeException");
     try {
         $result = $service->purchase();
     } catch (RuntimeException $e) {
         $this->markTestIncomplete();
         $totalNZD = Payment::get()->filter('MoneyCurrency', "NZD")->sum();
         $this->assertEquals(27.23, $totalNZD);
         $service->purchase();
         $service->completePurchase();
         //just to assert that exception is thrown
         throw $e;
     }
 }
Exemplo n.º 14
0
 /**
  * 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();
 }
 /**
  * Get the the payment according to the identifer given in the url
  * @return Payament the payment
  */
 private function getPayment()
 {
     return Payment::get()->filter('Identifier', $this->request->param('Identifier'))->filter('Identifier:not', "")->first();
 }
 /**
  * Check whether payment for the given registration succeeded. Returns true if so
  * 
  * @param type $registration
  */
 public function checkPayment($registration, $payment = null)
 {
     if (!$payment) {
         $paymentID = Session::get('PaymentID');
         if ($paymentID) {
             $payment = Payment::get()->byID($paymentID);
         }
     }
     $paid = false;
     if ($payment) {
         $payment->PaidForClass = 'EventRegistration';
         $payment->PaidForID = $registration->ID;
         $payment->PaidBy = Member::currentUserID();
         $payment->write();
         $registration->PaymentID = $payment->ID;
         if ($payment->Status == PaymentGateway_Result::SUCCESS) {
             $registration->Status = 'Valid';
             $paid = true;
             $registration->extend('onPaymentConfirmed', $payment->Status);
             Session::clear('PaymentID');
         }
         $registration->write();
     }
     return $paid;
 }
Exemplo n.º 17
0
 public function getPaymentStatus()
 {
     // Get the payment ID before session clear
     $payment_id = Session::get('paypal_payment_id');
     // clear the session payment ID
     Session::forget('paypal_payment_id');
     if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
         return Redirect::route('original.route')->with('error', 'Payment failed');
     }
     $payment = Payment::get($payment_id, $this->_api_context);
     // PaymentExecution object includes information necessary
     // to execute a PayPal account payment.
     // The payer_id is added to the request query parameters
     // when the user is redirected from paypal back to your site
     $execution = new PaymentExecution();
     $execution->setPayerId(Input::get('PayerID'));
     //Execute the payment
     $result = $payment->execute($execution, $this->_api_context);
     echo '<pre>';
     print_r($result);
     echo '</pre>';
     exit;
     // DEBUG RESULT, remove it later
     if ($result->getState() == 'approved') {
         // payment made
         return Redirect::route('original.route')->with('success', 'Payment success');
     }
     return Redirect::route('original.route')->with('error', 'Payment failed');
 }
 public function testPaymentIncomplete()
 {
     $config = $this->processor->gateway->getConfig();
     $PxPay_Url = Config::inst()->get('PaymentExpressGateway_PxPay', 'url');
     $PxPay_Userid = $config['authentication']['user_id'];
     //This should set up a redirect to the gateway for the browser in the response of the controller
     $this->data['mock'] = 'success';
     $this->processor->capture($this->data);
     //Test redirect to gateway
     $response = Controller::curr()->getResponse();
     $this->assertEquals($response->getHeader('Location'), "{$PxPay_Url}?userid={$PxPay_Userid}&request=v52CRsqBR5-mock");
     //Test payment completion after redirect from gateway
     $queryString = http_build_query(array('result' => 'v52GezCtXh1qqQ-mock', 'userid' => $PxPay_Userid, 'mock' => 'incomplete'));
     Director::test($this->processor->gateway->returnURL . "?{$queryString}");
     $payment = $payment = Payment::get()->byID($this->processor->payment->ID);
     $this->assertEquals($payment->Status, Payment::INCOMPLETE);
 }
 /**
  * Show a page after a payment is completed
  */
 function completed()
 {
     $paymentID = Session::get('PaymentID');
     $payment = Payment::get()->byID($paymentID);
     return array('Content' => $this->customise(array('Payment' => $payment))->renderWith('PaymentTestPage'));
 }
Exemplo n.º 20
0
    $pgrespcode = $_POST['pgRespCode'];
    $data .= $pgrespcode;
}
if (isset($_POST['addressZip'])) {
    $pincode = $_POST['addressZip'];
    $data .= $pincode;
}
if (isset($_POST['signature'])) {
    $signature = $_POST['signature'];
}
$respSignature = hash_hmac('sha1', $data, $secret_key);
if ($signature != "" && strcmp($signature, $respSignature) != 0) {
    $flag = "false";
}
$Payment = new Payment();
$details = $Payment->get($txnid);
if (!empty($details) && $flag == "true") {
    $comments = $_POST['TxMsg'];
    $status = "Paid";
    if ($txnstatus != "SUCCESS") {
        $status = "Failed";
    }
    $more_details = array('transaction_id' => $pgtxnno, 'status' => $status, 'comments' => $comments, 'payment_date' => $payment_date, 'postal_code' => $pincode);
    $SM = new SubscriptionManager();
    $package = $SM->getPackageDetails($details['package_id']);
    if (!empty($package)) {
        /*
         * 03-11-15 :: vj calculate ext payment date using last payment details
         * 18-11-15 :: vj : Purchase, Updgrade and Re-purchase has been handled 
         */
        $last_payment = $SM->getLastPaymentDetails($details['app_key'], 'Paid');
Exemplo n.º 21
0
 /**
  * Helper to get {@link Payment}s that are made against this Order
  * 
  * @return ArrayList Set of Payment objects
  */
 public function Payments()
 {
     return Payment::get()->where("\"OrderID\" = {$this->ID}");
 }
 /**
  * Create payments by generating XML and sending to Xero.
  * 
  * @param  XeroOAuth $XeroOAuth Connection to Xero
  */
 private function createPayments($XeroOAuth)
 {
     $xeroConnection = clone $XeroOAuth;
     $invoicePrefix = $this->config()->invoicePrefix;
     $defaultAccountPurchasesCode = $this->config()->defaultAccountPurchasesCode;
     $data = array();
     // Creating payments only for orders that have been created on Xero
     $orders = Order::get()->where(" \"XeroInvoiceID\" IS NOT NULL ");
     $i = 0;
     if ($orders && $orders->exists()) {
         foreach ($orders as $order) {
             $payments = $order->Payments();
             if ($payments && $payments->exists()) {
                 foreach ($payments as $payment) {
                     if ($payment->XeroPaymentID) {
                         continue;
                     }
                     $data[$i]['Payment'] = array('Invoice' => array('InvoiceID' => $order->XeroInvoiceID), 'Account' => array('Code' => $defaultAccountPurchasesCode), 'Date' => date('Y-m-d', strtotime($payment->Created)), 'Amount' => $payment->Amount->getAmount(), 'Reference' => $invoicePrefix . $payment->ID);
                     $i++;
                 }
             }
         }
     }
     // If no data do not send to Xero
     if (empty($data)) {
         return;
     }
     $paymentsXML = new SimpleXMLElement("<Payments></Payments>");
     $this->arrayToXML($data, $paymentsXML);
     $xml = $paymentsXML->asXML();
     $response = $xeroConnection->request('POST', $xeroConnection->url('Payments', 'core'), array(), $xml);
     if ($xeroConnection->response['code'] == 200) {
         $payments = $xeroConnection->parseResponse($xeroConnection->response['response'], $xeroConnection->response['format']);
         echo count($payments->Payments[0]) . " payments(s) created in this Xero organisation.";
         // Update payments that are sent to Xero so that they are not sent again
         foreach ($payments->Payments->Payment as $remittance) {
             $payment = Payment::get()->filter('ID', str_replace($invoicePrefix, '', $remittance->Reference->__toString()))->first();
             if ($payment && $payment->exists()) {
                 $payment->XeroPaymentID = $remittance->Reference->__toString();
                 $payment->write();
             }
         }
     } else {
         echo 'Error: ' . $xeroConnection->response['response'] . PHP_EOL;
         SS_Log::log(new Exception(print_r($xeroConnection, true)), SS_Log::NOTICE);
     }
 }