Example #1
0
 /**
  * @When /^test token is retrieved$/
  */
 public function testTokenIsRetrieved()
 {
     $tokenModel = new Paymentwall_OneTimeToken();
     $this->token = $tokenModel->create($this->getTestDetailsForOneTimeToken())->getToken();
     if (strpos($this->token, 'ot_') === FALSE) {
         throw new Exception($this->token->getPublicData());
     }
 }
 /**
  * Submit a payment through the PaymentWall Library.
  *
  * @param mixed $data
  *
  * @return Response
  */
 public function sendData($data)
 {
     // Initialise the PaymentWall configuration
     $this->setPaymentWallObject();
     // if no token exists, create one
     if (empty($data['purchase']['token'])) {
         // Create a one time token
         $tokenModel = new \Paymentwall_OneTimeToken();
         $tokenObject = $tokenModel->create($data['card']);
         if ($tokenObject->type == 'Error') {
             return $this->returnError($tokenObject->error, $tokenObject->code);
         }
         $data['purchase']['token'] = $tokenObject->getToken();
     }
     if (empty($data['purchase']['token'])) {
         return $this->returnError('Payment Token could not be created', 231);
     }
     // Now we know that we have an actual token (one time or
     // permanent), we can create the charge request.
     $charge = new \Paymentwall_Charge();
     try {
         $charge->create($data['purchase']);
     } catch (\Exception $e) {
         return $this->returnError('Cannot process payment', 231, $charge->getResponseLogInformation());
     }
     // Force the charge properties to be an array
     $properties = $charge->getProperties();
     $properties = json_decode(json_encode($properties), true);
     // Construct the response object
     $this->response = new Response($this, $properties);
     if ($charge->isSuccessful()) {
         if ($charge->isCaptured()) {
             $this->response->setCaptured(true);
         } elseif ($charge->isUnderReview()) {
             $this->response->setUnderReview(true);
         }
     }
     return $this->response;
 }
Example #3
0
function paymentwallbrick_storeremote($params)
{
    $email = $params['clientdetails']['email'];
    global $CONFIG;
    $systemurl = $CONFIG['SystemSSLURL'] ? $CONFIG['SystemSSLURL'] . '/' : $CONFIG['SystemURL'] . '/';
    if (!class_exists("Paymentwall_Config")) {
        require_once dirname(__FILE__) . "/paymentwallbrick/lib/paymentwall.php";
    }
    if ($params["test_mode"] == "on") {
        Paymentwall_Config::getInstance()->set(array('api_type' => Paymentwall_Config::API_GOODS, 'public_key' => $params['test_public_key'], 'private_key' => $params['test_private_key']));
    } else {
        Paymentwall_Config::getInstance()->set(array('api_type' => Paymentwall_Config::API_GOODS, 'public_key' => $params['public_key'], 'private_key' => $params['private_key']));
    }
    if ($params["action"] == "delete") {
        return array('status' => 'success');
    }
    if (isset($_POST['brick_token'])) {
        if (isset($_POST['ccupdate'])) {
            $charge = new Paymentwall_Charge();
            $charge->create(array('fingerprint' => $_POST['brick_fingerprint'], 'token' => $_POST['brick_token'], 'email' => $email, 'capture' => false, 'currency' => $params['currency'], 'amount' => 1, 'description' => 'Card Update - This charge will be automatically voided'));
            if ($charge->isSuccessful()) {
                $gatewayid = $charge->card->token;
                $_SESSION['paymentwall_card'] = $charge->card;
                $charge->void();
                return array('status' => 'success', 'gatewayid' => $gatewayid);
            } else {
                $response = $charge->getPublicData();
                $errors = json_decode($response, true);
                return array('status' => 'error', 'rawdata' => $errors['error']['message']);
            }
        } else {
            return array('status' => 'success', 'gatewayid' => "brickjs");
        }
    } elseif (isset($params['cardnum'])) {
        $tokenModel = new Paymentwall_OneTimeToken();
        $token = $tokenModel->create(array('public_key' => Paymentwall_Config::getInstance()->getPublicKey(), 'card[number]' => $params['cardnum'], 'card[exp_month]' => substr($params['cardexp'], 0, 2), 'card[exp_year]' => substr($params['cardexp'], 2, 2), 'card[cvv]' => $params['cardcvv']));
        $charge = new Paymentwall_Charge();
        $charge->create(array('token' => $token->getToken(), 'email' => $email, 'capture' => false, 'currency' => $params['currency'], 'amount' => 1, 'browser_ip' => $_SERVER['REMOTE_ADDR'], 'browser_domain' => $_SERVER['HTTP_HOST'], 'description' => 'Card Update - This charge will be automatically voided'));
        if ($charge->isSuccessful()) {
            $gatewayid = $charge->card->token;
            $charge->void();
            return array('status' => 'success', 'gatewayid' => $gatewayid);
        } else {
            $response = $charge->getPublicData();
            $errors = json_decode($response, true);
            return array('status' => 'error', 'rawdata' => $errors['error']['message']);
        }
    }
}