Example #1
0
 /**
  * Assert that a captured flag is set after charge is successfully captured.
  *
  * In our test environment, the charge will be auto-captured after create
  * and this test will raise OmiseFailedCaptureException.
  *
  */
 public function testCapture()
 {
     $charge = OmiseCharge::retrieve('chrg_test_4zmrjgxdh4ycj2qncoj');
     $charge->capture();
     $this->assertArrayHasKey('object', $charge);
     $this->assertEquals('charge', $charge['object']);
     $this->assertTrue($charge['captured']);
 }
Example #2
0
 /**
  * Assert that a reversed flag is set after charge is successfully reversed.
  *
  */
 public function testReverse()
 {
     $charge = OmiseCharge::retrieve('chrg_test_53z5zoeovi39e1erbj0');
     $charge->reverse();
     $this->assertArrayHasKey('object', $charge);
     $this->assertEquals('charge', $charge['object']);
     $this->assertTrue($charge['reversed']);
 }
 /**
  * Capture a charge that retrieve from charge id
  * @param array $params
  * @return OmiseCharge|Exception
  */
 public function captureOmiseCharge($id)
 {
     try {
         $charge = OmiseCharge::retrieve($id, $this->_public_key, $this->_secret_key);
         return $charge->capture();
     } catch (Exception $e) {
         return array('error' => $e->getMessage());
     }
 }
Example #4
0
 /**
  *
  */
 public function testRetrieveSpecificChargeRefundObject()
 {
     $charge = OmiseCharge::retrieve('chrg_test_4zmrjgxdh4ycj2qncoj');
     $refunds = $charge->refunds();
     $create = $refunds->create(array('amount' => 10000));
     $refund = $refunds->retrieve($create['id']);
     $this->assertArrayHasKey('object', $refund);
     $this->assertEquals('refund', $refund['object']);
 }
Example #5
0
 /**
  * Checkout orders and charge a card process
  * @return string(Json)
  */
 public function checkout()
 {
     // Define 'OMISE_USER_AGENT_SUFFIX'
     if (!defined('OMISE_USER_AGENT_SUFFIX') && defined('VERSION')) {
         define('OMISE_USER_AGENT_SUFFIX', 'OmiseOpenCart/1.5.0.2 OpenCart/' . VERSION);
     }
     // Define 'OMISE_API_VERSION'
     if (!defined('OMISE_API_VERSION')) {
         define('OMISE_API_VERSION', '2014-07-27');
     }
     // If has a `post['omise_token']` request.
     if (isset($this->request->post['omise_token'])) {
         // Load `omise-php` library.
         $this->load->library('omise/omise-php/lib/Omise');
         // Get Omise configuration.
         $omise = $this->config->get('Omise');
         // If test mode was enabled,
         // replace Omise live key with test key.
         if (isset($omise['test_mode']) && $omise['test_mode']) {
             $omise['public_key'] = $omise['public_key_test'];
             $omise['secret_key'] = $omise['secret_key_test'];
         }
         // Create a order history with `Processing` status
         $this->load->model('checkout/order');
         $order_id = $this->session->data['order_id'];
         $order_info = $this->model_checkout_order->getOrder($order_id);
         $order_total = number_format($order_info['total'], 2, '', '');
         if ($order_info) {
             try {
                 // Try to create a charge and capture it.
                 $omise_charge = OmiseCharge::create(array("amount" => $order_total, "currency" => 'thb', "description" => $this->request->post['description'], "card" => $this->request->post['omise_token']), $omise['public_key'], $omise['secret_key']);
                 if (is_null($omise_charge['failure_code']) && is_null($omise_charge['failure_code']) && $omise_charge['captured']) {
                     // Status: processed.
                     $this->model_checkout_order->confirm($order_id, 15);
                 } else {
                     // Status: failed.
                     $this->model_checkout_order->update($order_id, 10);
                 }
                 echo json_encode(array('failure_code' => $omise_charge['failure_code'], 'failure_message' => $omise_charge['failure_message'], 'captured' => $omise_charge['captured'], 'omise' => $omise_charge));
             } catch (Exception $e) {
                 // Status: failed.
                 $this->model_checkout_order->update($this->session->data['order_id'], 10);
                 echo json_encode(array('error' => $e->getMessage()));
             }
         } else {
             echo json_encode(array('error' => 'Cannot find your order, please try again.'));
         }
     } else {
         return 'not authorized';
     }
 }
Example #6
0
 private function charge_Create($dataArray)
 {
     if (isset($dataArray['omise_token'])) {
         // Charge a card.
         $data2send = array('amount' => $this->moneySatang($dataArray['amount']), 'currency' => 'thb', 'card' => $dataArray['omise_token'], 'return_uri' => $dataArray['return_uri'], 'description' => $dataArray['description']);
         try {
             // send chart info to omise and store result
             $charge = OmiseCharge::create($data2send);
             // set default response to error
             $displayResult['ok'] = 0;
             $displayResult['msg'] = "";
             $displayResult['data'] = array();
             // check if parameter exist
             if ($charge['object'] === 'charge' && $charge['authorized'] && $charge['capture'] && $charge['captured']) {
                 // check if no error
                 if ($charge['failure_code'] === NULL || $charge['failure_code'] === "null" || $charge['failure_code'] === "") {
                     // check if transaction success
                     if ($charge['authorized'] === true && $charge['captured'] === true) {
                         $displayResult['ok'] = 1;
                         $displayResult['msg'] = "payment complete";
                         $displayResult['data'] = (array) $charge;
                     } else {
                         // error
                         $displayResult['msg'] = 'card unauthorize';
                         $displayResult['data'] = (array) $charge;
                     }
                 } else {
                     // error
                     $displayResult['msg'] = "card error: (" . (array) $charge['failure_code'] . ') ' . (array) $charge['failure_message'];
                 }
             }
         } catch (OmiseException $e) {
             $displayResult['msg'] = $e->getMessage();
         }
         return $displayResult;
     } else {
         return array('ok' => 0, 'msg' => 'no token');
     }
 }
Example #7
0
<?php

$charge = OmiseCharge::retrieve("chrg_test_4xso2s8ivdej29pqnhz");
$refund = $charge->refunds()->create(array('amount' => 10000));
Example #8
0
<?php

$charge = OmiseCharge::create(array('amount' => 100000, 'currency' => 'thb', 'card' => 'tokn_test_4xs9408a642a1htto8z'));
<?php

// print_r($_POST);
require_once dirname(__FILE__) . '/omise-php/lib/Omise.php';
// This example using Omise API version 2014-07-27
define('OMISE_API_VERSION', '2014-07-27');
// Your Omise public and secret keys can get from your Omise test/live dashboards.
define('OMISE_PUBLIC_KEY', '');
define('OMISE_SECRET_KEY', '');
if (isset($_POST['omise_token'])) {
    $token = $_POST['omise_token'];
}
if (isset($_POST['amount'])) {
    $checkout_amount = $_POST['amount'];
}
if (isset($_POST['description'])) {
    $checkout_description = $_POST['description'];
}
try {
    $charge = OmiseCharge::create(array('livemode' => 'true', 'amount' => $checkout_amount, 'currency' => 'thb', 'card' => $token, 'description' => $checkout_description));
    // $capture = OmiseCarge::retrive(array(
    // ));
    // return $charge->capture();
} catch (Exception $e) {
    // echo $e;
    echo 'Caught exception: ', $e->getMessage(), "\n";
}
Example #10
0
<?php

$charge = OmiseCharge::create(array('amount' => 100000, 'currency' => 'thb', 'customer' => 'cust_test_4xtrb759599jsxlhkrb'));
Example #11
0
<?php

$charge = OmiseCharge::create(array('amount' => 100000, 'currency' => 'thb', 'customer' => 'cust_test_4xtrb759599jsxlhkrb', 'card' => 'card_test_4xtsoy2nbfs7ujngyyq'));
Example #12
0
<?php

$charges = OmiseCharge::retrieve();