[quote pid="393897" dateline="1644885998"]
HELLO, how could I retrieve the data that was sent to me from another server by php,
example the Host website:
www.coinpayments.net send some responses via HTTP to my website when an order is purchased but I couldn't understand how to capture said data since if I perform the process outside of codeigniter 4 it works without any problem but with codeigniter the project does not work and it does not update the data that the other website sends me
no codeigniter 4
Code:
/////Index///
<?php
require "init.php";
$basicInfo = $cps_api->GetBasicInfo();
$username = $basicInfo['result']['public_name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accept Cryptocurrency</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="/js/particles.min.js"></script>
<style>
canvas {
background-image: url("img/bg.jpeg");
background-repeat: no-repeat;
background-size: 100% 100%;
position: fixed;
display: block;
top: 0;
left: 0;
z-index: 0;
}
</style>
<script>
particlesJS.load("particles-js", "json/particles.json", function() {
console.log("particles loaded");
});
</script>
</head>
<body>
<div id="particles-js"></div>
<br><br><br>
<div id="app" class="container">
<div class="row">
<div class="col-md-6 offset-md-3" style="margin:auto; background: white; padding: 20px; box-shadow: 10px 10px 5px #888;">
<div class="panel-heading">
<h1>Pay with cryptocurrency</h1>
<p style="font-style: italic;">to <strong><?php echo $username; ?></strong></p>
</div>
<hr>
<form action="process.php" method="post" autocomplete="off">
<label for="amount">Amount (USD)</label>
<input type="text" name="amount" class="form-control">
<br>
<label for="email">Email Address</label>
<input type="email" name="email" class="form-control">
<br>
<button type="submit" style="border-radius: 0px;" class="btn btn-lg btn-block btn-success">Pay to <?php echo $username; ?></button>
</form>
</div>
</div>
</div>
</body>
</html>
Code:
////init/////
<?php
require "vendor/coinpaymentsnet/coinpayments-php/src/CoinpaymentsAPI.php";
require "vendor/autoload.php";
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => "mysql",
'host' => "localhost",
'database' => "******",
'username' => "******",
'password' => "****o:0Pp"
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require "Payment.php";
$private_key = "*******7E5C7db92b5ded7E8F8f043DCcec49cfcA4107a";
$public_key ="********b7d0ec50f3041170af449d236f6f19e96e70c09fb3ee8";
$cps_api = new CoinpaymentsAPI($private_key, $public_key, 'json');
?>
Code:
///payment///
<?php
use Illuminate\Database\Eloquent\Model as Eloquent;
/**
* Payment
*/
class Payment extends Eloquent
{
protected $table = "payments";
}
[/quote]
Code:
///proceess////
<?php
require "init.php";
$basicInfo = $cps_api->GetBasicInfo();
$username = $basicInfo['result']['public_name'];
$amount = $_POST['amount'];
$email = $_POST['email'];
$scurrency = "USD";
$rcurrency = "LTCT";
$address = '';
$buyer_name = 'John Blockchain';
$item_name = 'Fancy Dongle';
$item_number = '2018';
$custom = 'Express order';
$invoice = 'JB-2018-1';
$ipn_url = "https:///////*******/ve/pruba_conpatmets/webhook.php";
$result = $cps_api ->CreateCustomTransaction([
'amount' => $amount,
'currency1' => $scurrency,
'currency2' => $rcurrency,
'item_name' => $item_name ,
'item_number' => $item_name,
'invoice' => 'JB-2018-1',
'ipn_url' => $ipn_url,
//'timeout' => 86399,
'buyer_email' => $email,//$this->usuario->email,
]);
var_dump($result);
if ($result['error'] == "ok") {
$payment = new Payment;
$payment->email = $email;
$payment->entered_amount = $amount;
$payment->amount = $result['result']['amount'];
$payment->from_currency = $scurrency;
$payment->to_currency = $rcurrency;
$payment->status = "initialized";
$payment->gateway_id = $result['result']['txn_id'];
$payment->gateway_url = $result['result']['status_url'];
$payment->save();
} else {
print 'Error: ' . $result['error'] . "\n";
die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accept Cryptocurrency</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="/js/particles.min.js"></script>
<style>
canvas {
background-image: url("/images/bg.jpeg");
background-repeat: no-repeat;
background-size: 100% 100%;
position: fixed;
display: block;
top: 0;
left: 0;
z-index: 0;
}
</style>
<script>
particlesJS.load("particles-js", "json/particles.json", function() {
console.log("particles loaded");
});
</script>
</head>
<body>
<div id="particles-js"></div>
<br><br><br>
<div id="app" class="container">
<div class="row">
<div class="col-md-6 offset-md-3" style="margin:auto; background: white; padding: 20px; box-shadow: 10px 10px 5px #888;">
<div class="panel-heading">
<h1>Pay with cryptocurrency</h1>
<p style="font-style: italic;">to <strong><?php echo $username; ?></strong></p>
</div>
<hr>
<form>
<label for="amount">Amount (<?php echo $rcurrency; ?>)</label>
<h1><?php echo $result['result']['amount'] ?> <?php echo $rcurrency ?></h1>
<hr>
<a href="<?php echo $result['result']['status_url'] ?>" class="btn btn-success btn-block">Pay Now</a>
</form>
</div>
</div>
</div>
</body>
</html>
Code:
////webhook///
<?php
require "init.php";
$merchant_id = "******5cce6b471679b43e";
$ipn_secret = "///998/AzUleAIM";
$debug_email = "";
$txn_id = $_POST['txn_id'];
$payment = Payment::where("gateway_id", $txn_id)->first();
$order_currency = $payment->to_currency; //BTC
$order_total = $payment->amount; //BTC
function edie($error_msg)
{
global $debug_email;
$report = "ERROR : " . $error_msg . "\n\n";
$report.= "POST DATA\n\n";
foreach ($_POST as $key => $value) {
$report .= "|$k| = |$v| \n";
}
mail($debug_email, "Payment Error", $report);
die($error_msg);
}
if (!isset($_POST['ipn_mode']) || $_POST['ipn_mode'] != 'hmac') {
edie("IPN Mode is not HMAC");
}
if (!isset($_SERVER['HTTP_HMAC']) || empty($_SERVER['HTTP_HMAC'])) {
edie("No HMAC Signature Sent.");
}
$request = file_get_contents('php://input');
if ($request === false || empty($request)) {
edie("Error in reading Post Data");
}
if (!isset($_POST['merchant']) || $_POST['merchant'] != trim($merchant_id)) {
edie("No or incorrect merchant id.");
}
$hmac = hash_hmac("sha512", $request, trim($ipn_secret));
if (!hash_equals($hmac, $_SERVER['HTTP_HMAC'])) {
edie("HMAC signature does not match.");
}
$amount1 = floatval($_POST['amount1']); //IN USD
$amount2 = floatval($_POST['amount2']); //IN BTC
$currency1 = $_POST['currency1']; //USD
$currency2 = $_POST['currency2']; //BTC
$status = intval($_POST['status']);
if ($currency2 != $order_currency) {
edie("Currency Mismatch");
}
if ($amount2 < $order_total) {
edie("Amount is lesser than order total");
}
if ($status >= 100 || $status == 2) {
// Payment is complete
$payment->status = "success";
$payment->save();
} else if ($status < 0) {
// Payment Error
$payment->status = "error";
$payment->save();
} else {
// Payment Pending
$payment->status = "pending";
$payment->save();
}
die("IPN OK");
if you consult everything it works without any problem but when you do it in codeigniter it doesn't work
Code:
$routes->get('/', 'Home::index');
$routes->post('process', 'Home::process');
$routes->post('webhook', 'Webhook::index');
Code:
<?php
namespace App\Controllers;
use CoinpaymentsAPI;
class Home extends BaseController
{
public function index()
{
$private_key = "54545454547E8F8f043DCcec49cfcA4107a";
$public_key ="454544549d236f6f19e96e70c09fb3ee8";
$cps_api = new CoinpaymentsAPI($private_key, $public_key, 'json');
$basicInfo = $cps_api->GetBasicInfo();
$username = $basicInfo['result']['public_name'];
return view('welcome_message',[
'username' => $username,
]);
}
public function process()
{
$private_key = "45455454b92b5ded7E8F8f043DCcec49cfcA4107a";
$public_key ="4545454546f6f19e96e70c09fb3ee8";
$cps_api = new CoinpaymentsAPI($private_key, $public_key, 'json');
$amount = $this->request->getPostGet('amount');
$email = $this->request->getPostGet('email');
$basicInfo = $cps_api->GetBasicInfo();
$username = $basicInfo['result']['public_name'];
$scurrency = "USD";
$rcurrency = "LTCT";
$address = '';
$buyer_name = 'John Blockchain';
$item_name = 'Fancy Dongle';
$item_number = '2018';
$custom = 'Express order';
$invoice = 'JB-2018-1';
$result = $cps_api ->CreateCustomTransaction([
'amount' => $amount,
'currency1' => $scurrency,
'currency2' => $rcurrency,
'item_name' => $item_name ,
'item_number' => $item_name,
'invoice' => 'JB-2018-1',
'ipn_url' => base_url('webhook'),
//'timeout' => 86399,
'buyer_email' => $email,//$this->usuario->email,
]);
if ($result['error'] == "ok") {
$data = [
'email' => $email,
'entered_amount' => $amount,
'amount' => $result['result']['amount'],
'from_currency' => $scurrency,
'to_currency' => $rcurrency,
'status' => 'initialized',
'gateway_id' => $result['result']['txn_id'],
'gateway_url' => $result['result']['status_url'],
];
model('Compra')->save($data);
} else {
print 'Error: ' . $result['error'] . "\n";
die();
}
return view('process',[
'scurrency' =>$scurrency,
'rcurrency' => $rcurrency,
'username' => $username,
'result' => $result,
]);
}
}
/////web//
}