Example #1
0
    public function sendPayment($total, $paramurl)
    {
        $cart = $this->context->cart;
        $payment = array('amount' => $total, 'currency' => 'EUR', 'customerData' => $cart->id, 'paymentSuccessUrl' => $this->context->link->getModuleLink('nimblepayment', 'paymentok', array('paymentcode' => $paramurl)), 'paymentErrorUrl' => $this->context->link->getModuleLink('nimblepayment', 'paymentko', array('paymentcode' => $paramurl)));
        try {
            $p = new Payments();
            $response = $p->SendPaymentClient($this->nimbleapi, $payment);
        } catch (Exception $e) {
            //type error = 3 // problem to send payment
            $this->type_error = $this->module->l('Is not possible to send the payment to Nimble Payments. Sorry for the inconvenience.');
            Logger::addLog('NIMBLE_PAYMENTS. Is not possible to send the payment.', 4);
            $this->setTemplate('payment_failed.tpl');
            return false;
        }
        if (empty($response)) {
            //type error = 6
            $this->type_error = $this->module->l('Unknown error or timeout. Sorry for the inconvenience.');
            Logger::addLog('NIMBLE_PAYMENTS. Unknown error or timeout.', 4);
            $this->setTemplate('payment_failed.tpl');
        } elseif (!isset($response['error'])) {
            if ($response['result']['code'] == 200) {
                //save transaction_id in session. After in validateOrder (paymentok.php) we will use transaction_id
                $this->context->cookie->__set('nimble_transaction_id', $response['data']['id']);
                //Tools::redirect($response['data'][0]['paymentUrl']); //old version
                Tools::redirect($response['data']['paymentUrl']);
            } elseif ($response['result']['code'] == 401) {
                //type error = 7 // 401 unauthorized
                $this->setTemplate('payment_failed.tpl');
                $this->type_error = $this->module->l('Unauthorized access. Please an administrator user should check the credentials 
					and the selected environment to access Nimble Payments. Sorry for the inconvenience.');
                Logger::addLog('NIMBLE_PAYMENTS. Unauthorized access. Please an administrator user should check the credentials 
					and the selected environment to access Nimble Payments. (Code Error: ' . $response['result']['code'] . ')', 4);
            } else {
                //type error = 4 // problem to send payment 2
                $this->setTemplate('payment_failed.tpl');
                $this->type_error = $this->module->l('Is not possible send to the payment to Nimble Payments. Sorry for the inconvenience.
				 Code Error: ') . $response['result']['code'];
                Logger::addLog('NIMBLE_PAYMENTS. Is not possible send to the payment to Nimble Payments (Code Error: ' . $response['result']['code'] . ')', 4);
            }
        } else {
            //type error = 5 // problem to send payment 3
            $this->type_error = $this->module->l('We have received an error from Nimble Payments. Sorry for the inconvenience. Error: ') . $response['error'];
            $this->setTemplate('payment_failed.tpl');
            Logger::addLog('NIMBLE_PAYMENTS. We have received an error from Nimble Payments (Error: ' . $response['error'] . ')', 4);
        }
    }
Example #2
0
//show code
highlight_file("/info/payment_send.php");
?>
<br />
------------------------------------------------------------------------------------------------------------
<br />

<?php 
require_once '../lib/Nimble/base/NimbleAPI.php';
$payment = array('amount' => 1010, 'currency' => 'EUR', 'customerData' => 'idSample12345', 'paymentSuccessUrl' => 'https://my-commerce.com/payments/success', 'paymentErrorUrl' => 'https://my-commerce.com/payments/error');
$params = array('clientId' => '729DFCD7A2B4643A0DA3D4A7E537FC6E', 'clientSecret' => 'jg26cI3O1mB0$eR&fo6a2TWPmq&gyQoUOG6tClO%VE*N$SN9xX27@R4CTqi*$4EO', 'mode' => 'demo');
/* High Level call */
$NimbleApi = new NimbleAPI($params);
$p = new Payments();
$response = $p->SendPaymentClient($NimbleApi, $payment);
?>

<?php 
/* Low Level call */
$NimbleApi = new NimbleAPI($params);
$NimbleApi->setPostfields(json_encode($payment));
$NimbleApi->uri = ConfigSDK::NIMBLE_API_BASE_URL . 'payments';
$NimbleApi->method = 'POST';
$response2 = $NimbleApi->rest_api_call();
?>

<br /><pre>
Response: (var_dump($response))
<?php 
var_dump($response);