Stuck while using call_back_address and ipn url in coinpayment.net gateway

0 votes

I'm using coinpayment gateway api (cmd=create_transfer). I generated qr code and address those are successfully scanned from app but after payment I want to redirect success_url and other information submitted into database.

<?php
/*
  CoinPayments.net API Example
  Copyright 2016 CoinPayments.net. All rights reserved.
  License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.txt
 */
require('./coinpayments.inc.php');
$cps = new CoinPaymentsAPI();
$public_key = "xxx";
$private_key = "xxx";
$cps->Setup($private_key, $public_key);

$req = array(
    'amount' => $_POST['amount'],
    'currency1' => "USD",
    'currency2' => "BTC",
    'address' => '', // leave blank send to follow your settings on the Coin Settings page
//      'item_name' => $_POST['item_name']
    print 'ipn_url' => $_POST['ipn_url'],
    print 'txn_id' => $_POST['txn_id'],
    print 'status' => intval($_POST['status']),
    print 'status_text' => $_POST['status_text']
);
// See https://www.coinpayments.net/apidoc-create-transaction for all of the available fields

$result = $cps->CreateTransaction($req);
if ($result['error'] == 'ok') {
    $le = php_sapi_name() == 'cli' ? "\n" : '<br />';
    ?>
    <div class="col-4">
        <h2><?php print 'Buyer should send ' . sprintf('%.08f', $result['result']['amount']) . ' BTC' . $le; ?></h2>


        <img width="220" height="220" alt="" src="https://blockchain.info/qr?data=bitcoin:<?php echo $result['result']['address']; ?>?amount=<?php echo $result['result']['amount']; ?>%26label=example%2520label">

        <?php
    } else {
        print 'Error: ' . $result['error'] . "\n";
    }
    ?>
Aug 31, 2018 in Blockchain by slayer
• 29,040 points
191 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

To make use of this api, just add this function in coinpayments.inc.php

}

public function GetTransactionInformation($txId) {      
$req = array(
    'txid' => $txId,

);
return $this->api_call('get_tx_info', $req);
}

Add this in you's script before printing tx id $txid = strip_tags($_POST['txn_id']) And for results

 $cps = new CoinPaymentsAPI();
 $cps->Setup('Your_Private_Key', 'Your_Public_Key');
 $result = $cps->GetTransactionInformation('$txid');
  //get the array info of transaction
  if ($result['error'] == 'ok') {
  print_r ($result);
 } else {
print 'Error: '.$result['error']."\n";
 }

You should get result in Array. For getting in Json output just replace.

 print_r ($result);

With

 print $result['result']['status']
answered Aug 31, 2018 by digger
• 27,620 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
1,729 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
77 views
0 votes
1 answer
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 27,620 points
102 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.