Тема: Проблема оплати WayForPay
Доброго дня.
Написав интеграцию з WayForPay
Передививсь все я не сильно розумию php
Отже проблема в тому ,що кошти з нимае, зараховуеться.
А от коли покупець вводить карту де немае коштив вейфорпей видмовляе ,а от на баланс зараховуеться не можу зрозумать в чому проблема де допустив помилку.
Допоможить будь-ласка
Не знаю чому але не видображаються букви і і є
Ось сам код ,буду дуже вдячний
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class wayforpay extends MX_Controller {
public $tb_users;
public $tb_transaction_logs;
public $payment_type;
public $currency_code;
public $mode;
public function __construct(){
parent::__construct();
$this->tb_users = USERS;
$this->tb_transaction_logs = TRANSACTION_LOGS;
$this->payment_type = "wayforpay";
$this->currency_code = "UAH";
$this->load->model('model', 'model');
}
public function index(){
redirect(cn("add_funds"));
}
/**
*
* Create payment
*
*/
public function create_payment(){
$amount = session("amount");
if (!empty($amount) && $amount > 0) {
$order_id = session("uid").'-'.sha1(microtime(true));
$date = new DateTime();
$orderDate = $date->getTimestamp();
$productName = array('Пополнение баланса');
$productPrice = array($amount);
$productCount = array(1);
$datas = array(
get_option('wayforpay_client_id'),
'https://smmua.top',
$order_id,
$orderDate,
$amount,
$this->currency_code,
'Пополнение баланса',
'1',
''.$amount.'',
);
$sign = hash_hmac('md5', implode(';', $datas), get_option('wayforpay_client_secret'));
$payload = array(
'transactionType' => 'CREATE_INVOICE',
'merchantAccount' => get_option('wayforpay_client_id'),
'merchantDomainName' => 'https://smmua.top',
'merchantAuthType' => 'SimpleSignature',
'apiVersion' => 1,
'merchantSignature' => $sign,
'orderReference' => $order_id,
'orderDate' => $orderDate,
'amount' => $amount,
'serviceUrl' => 'https://smmua.top/add_funds/wayforpay/complete',
'currency' => $this->currency_code,
'productName' => $productName,
'productPrice' => $productPrice,
'productCount' => $productCount
);
$ch = curl_init('https://api.wayforpay.com/api');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_HEADER, false);
$r = curl_exec($ch);
curl_close($ch);
$url = json_decode($r, true);
unset_session("amount");
unset_session("real_amount");
header('Location: '.$url['invoiceUrl']);
}else{
redirect(cn("add_funds"));
}
}
/**
*
* Call Execute payment after creating payment
*
*/
public function complete(){
$data = json_decode(file_get_contents('php://input'), true);
$exists_txnid = $this->model->get('id, transaction_id', $this->tb_transaction_logs, ['transaction_id' => $data['orderReference']]);
$datas = array(
get_option('wayforpay_client_id'),
$data['orderReference'],
$data['amount'],
$this->currency_code,
$data['authCode'],
$data['cardPan'],
$data['transactionStatus'],
$data['reasonCode']
);
$sign = hash_hmac('md5', implode(';', $datas), get_option('wayforpay_client_secret'));
if($sign == $data['merchantSignature'] && empty($exists_txnid)){
$uid = explode('-', $data['orderReference']);
$chagre_fee = get_option('wayforpay_chagre_fee');
/*---------- Add funds to user balance ----------*/
$datas = array(
"ids" => ids(),
"uid" => $uid[0],
"type" => $this->payment_type,
"transaction_id" => $data['orderReference'],
"amount" => $data['amount'],
"created" => NOW,
);
$this->db->insert($this->tb_transaction_logs, $datas);
$transaction_id = $this->db->insert_id();
$user_balance = get_field($this->tb_users, ["id" => $uid[0]], "balance");
$user_balance += ($data['amount'] * 100)/(100+ $chagre_fee);
$this->db->update($this->tb_users, ["balance" => $user_balance], ["id" => $uid[0]]);
/*---------- Send payment notification email ----------*/
if (get_option("is_payment_notice_email", '')) {
$CI = &get_instance();
if(empty($CI->payment_model)){
$CI->load->model('model', 'payment_model');
}
$check_send_email_issue = $CI->payment_model->send_email(get_option('email_payment_notice_subject', ''), get_option('email_payment_notice_content', ''), $uid[0]);
if($check_send_email_issue){
ms(array(
"status" => "error",
"message" => $check_send_email_issue,
));
}
}
$date = new DateTime();
$orderDate = $date->getTimestamp();
$shook = array(
$data['orderReference'],
'accept',
$orderDate
);
$signhook = hash_hmac('md5', implode(';', $shook), get_option('wayforpay_client_secret'));
$answer = array(
'orderReference' => $data['orderReference'],
'status' => 'accept',
'time' => $orderDate,
'signature' => $signhook
);
echo json_encode($answer);
set_session("transaction_id", $transaction_id);
}else{
echo 'bad sign';
}
}
}