1

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";
    }
    ?>

enter image description here

wowkin2
  • 5,895
  • 5
  • 23
  • 66
Mukesh Kumar
  • 57
  • 2
  • 7

2 Answers2

-1

Please refer here :- https://www.coinpayments.net/apidoc-get-tx-info. 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']

Replace status with other arrays and modify your page accordingly. Status has following numericals:- <0 Error, 0-99 Pending, 100 Completed/Paid

-2

If you are wanting offsite checkout you'd want to be using the Simple or Advanced buttons, the 'create_transaction' API is for making your own custom checkout pages.

Please check this link for the Simple or Advanced buttons: Coinpayments Simple and Advanced buttons link.

Edit
  • 29
  • 1
  • 3
  • 9