How can I use IPN for currency payments? https://www.coinpayments.net/merchant-tools-ipn
I created a file and put the IPN code there, but what do I have to do "run form post" this file? Do I have to create an API?
What I wanted with IPN was that when the payout was successful, I would execute a function in SQL.
But if the payment is made by the button of payments of currencies in my site (configured with POST FIELDS) nothing happens, even putting IPN URL of my site
Can someone help me?
IPN code:
<?php
$merchant_id = 'mymerchantid';
$secret = 'mysecretipn';
$cp_debug_email = 'myemaildebug';
function errorAndDie($error_msg) {
global $cp_debug_email;
if (!empty($cp_debug_email)) {
$report = 'Error: '.$error_msg."\n\n";
$report .= "POST Data\n\n";
foreach ($_POST as $k => $v) {
$report .= "|$k| = |$v|\n";
}
mail($cp_debug_email, 'CoinPayments IPN Error', $report);
}
die('IPN Error: '.$error_msg);
}
if (!isset($_POST['ipn_mode']) || $_POST['ipn_mode'] != 'hmac') {
$ipnmode = $_POST['ipn_mode'];
errorAndDie("IPN Mode is not HMAC $ipnmode");
}
if (!isset($_SERVER['HTTP_HMAC']) || empty($_SERVER['HTTP_HMAC'])) {
errorAndDie("No HMAC signature sent");
}
$merchant = isset($_POST['merchant']) ? $_POST['merchant']:'';
if (empty($merchant)) {
errorAndDie("No Merchant ID passed");
}
if (!isset($_POST['merchant']) || $_POST['merchant'] != trim($merchant_id)) {
errorAndDie('No or incorrect Merchant ID passed');
}
$request = file_get_contents('php://input');
if ($request === FALSE || empty($request)) {
errorAndDie("Error reading POST data");
}
$hmac = hash_hmac("sha512", $request, $secret);
if ($hmac != $_SERVER['HTTP_HMAC']) {
errorAndDie("HMAC signature does not match");
}
// HMAC Signature verified at this point, load some variables.
$status = intval($_POST['status']);
$status_text = $_POST['status_text'];
$txn_id = $_POST['txn_id'];
$currency1 = $_POST['currency1'];
$currency2 = $_POST['currency2'];
$amount1 = floatval($_POST['amount1']);
$amount2 = floatval($_POST['amount2']);
$order_currency = 'USD';
$order_total = $amount1;
$subtotal = $_POST['subtotal'];
$shipping = $_POST['shipping'];
///////////////////////////////////////////////////////////////
// Check the original currency to make sure the buyer didn't change it.
if ($currency1 != $order_currency) {
errorAndDie('Original currency mismatch!');
}
if ($amount1 < $order_total) {
errorAndDie('Amount is less than order total!');
}
if ($status >= 100 || $status == 2) {
//my code SQL
}
} else if ($status < 0) {
//my code SQL
} else {
//my code SQL
}
}
die('IPN OK');
?>
My code BUTTON COINPAYMENTS:
<form action="https://www.coinpayments.net/index.php" method="post">
<input type="hidden" name="cmd" value="_pay_simple">
<input type="hidden" name="reset" value="1">
<input type="hidden" name="merchant" value="mymerchant">
<input type="hidden" name="currency" value="USD">
<input type="hidden" name="custom" value="<?php echo $value?>">
<input type="hidden" name="amountf" value="<?php echo $value?>">
<input type="hidden" name="item_name" value="Testing"?>">
<input type="hidden" name="invoice" value="Testing">
<input type="hidden" name="allow_amount" value="1">
<input type="hidden" name="allow_currency" value="1">
<input type="hidden" name="allow_currencies" value="BTC,LTC,DOGE,ETH,BCH,DASH,ETC,BCN,POT,XVG,ZEC,ZEN,PPC,BLK,CURE,CRW,DCR,GLD,CLUB,BITB,BRK,CLOAK,DGB,EBST,EXP,FLC,GRS,KMD,KRS,LEC,LSK,MUE,NAV,NEO,NMC,NXT,PINK,PIVX,POA,PROC,QTUM,SMART,SNBL,SOXAX,STEEM,STRAT,SYS,TPAY,TRIG,UBQ,UNIT,VTC,WAVES,XCP,XEM,XMR,XSN,XZC">
<input type="hidden" name="success_url" value="mysuccesurl">
<input type="hidden" name="cancel_url" value="mycancelurl">
<input type="hidden" name="ipn_url" value="myipnurl">
<input type="hidden" name="email" value="<?php echo getEmail($login)?>">
<input type="hidden" name="first_name" value="<?php echo getName($login)?>">
<input type="hidden" name="last_name" value="<?php echo getLastName($login)?>">
<br>
<br>
<div align="center">
<button class="btn btn-success" type="submit">SUBMIT</button><br>
</div>
</form>