here's my code so far for the catalog/controller
Code: Select all
<?php
class ControllerPaymentVivaWallet extends Controller {
public function index() {
$this->language->load('payment/viva_wallet');
$data['text_wait'] = $this->language->get('text_wait');
$data['text_loading'] = $this->language->get('text_loading');
$data['help_start_date'] = $this->language->get('help_start_date');
$data['help_issue'] = $this->language->get('help_issue');
$data['button_confirm'] = $this->language->get('button_confirm');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/viva_wallet.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/payment/viva_wallet.tpl', $data);
} else {
return $this->load->view('default/template/payment/viva_wallet.tpl', $data);
}
}
public function send() {
if (!$this->config->get('viva_wallet_transaction')) {
$payment_type = 'Authorization';
} else {
$payment_type = 'Sale';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if (!$this->config->get('viva_wallet_test')) {
$request = 'https://www.vivapayments.com/api/orders'; //live
} else {
$request = 'http://demo.vivapayments.com/api/orders'; //demo
}
$AllowRecurring = 'false'; // This flag will prompt the customer to accept recurring payments in tbe future.
$RequestLang = 'el-GR'; //This will display the payment page in English (default language is Greek)
$Source = ''; // This will assign the transaction to the Source with Code = "Default". If left empty, the default source will be used.
$Amount = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);// 100; // Amount in cents
$postargs = 'Amount='.urlencode($Amount).'&AllowRecurring='.$AllowRecurring.'&RequestLang='.$RequestLang.'&SourceCode='.$Source;
$MerchantId = urlencode($this->config->get('viva_wallet_username'));
$APIKey = urlencode($this->config->get('viva_wallet_password'));
$session = curl_init($request);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_USERPWD, $MerchantId.':'.$APIKey);
$response = curl_exec($session);
// Separate Header from Body
$header_len = curl_getinfo($session, CURLINFO_HEADER_SIZE);
$resHeader = substr($response, 0, $header_len);
$resBody = substr($response, $header_len);
curl_close($session);
// Parse the JSON response
/* try {
if(is_object(json_decode($resBody))){
$resultObj=json_decode($resBody);
}else{
preg_match('#^HTTP/1.(?:0|1) [\d]{3} (.*)$#m', $resHeader, $match);
throw new Exception("API Call failed! The error was: ".trim($match[1]));
}
}
catch( Exception $e ) {
echo $e->getMessage();
}
if ($resultObj->ErrorCode==0){ //success when ErrorCode = 0
$orderId = $resultObj->OrderCode;
echo 'Your Order Code is: <b>'. $orderId.'</b>';
echo '<br/><br/>';
echo 'To simulate a successfull payment, use the credit card 4111 1111 1111 1111, with a valid expiration date and 111 as CVV2.';
echo '</br/><a href="http://demo.vivapayments.com/web/newtransaction.aspx?ref='.$orderId.'" >Make Payment</a>';
}else{
echo 'The following error occured: ' . $resultObj->ErrorText;
} */
if (!$response) {
$this->log->write('DoDirectPayment failed: ' . curl_error($session) . '(' . curl_errno($session) . ')');
}
$response_info = array();
parse_str($response, $response_info);
$json = array();
if ($response_info['ErrorCode'] == '0') {
$message = '';
if (isset($response_info['TimeStamp'])) {
$message .= 'TimeStamp: ' . $response_info['TimeStamp'] . "\n";
}
if (isset($response_info['ErrorText'])) {
$message .= 'ErrorText: ' . $response_info['ErrorText'] . "\n";
}
if (isset($response_info['OrderCode'])) {
$message .= 'OrderCode: ' . $response_info['OrderCode'] . "\n";
}
$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('viva_wallet_order_status_id'), $message, false);
$json['success'] = $this->url->link('checkout/success');
} else {
$json['error'] = $response_info['L_LONGMESSAGE0'];
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
notice i've removed the JSON response that was with the original supplied vivapayment coding.... and instead used the oc JSON
i've tried both ways with the supplied json and with oc cart json and with both...
there seems to be no response from the server, and if there is, it's not letting oc cart know what's happening to complete the checkout....