Jump to content

Custom Field in pdf invoice


webpoint

Recommended Posts

Hi all,

 

We use bitcoin for payments, and for payment processor we use coinpayments.net.

Our accountant needs to see the bitcoin amount on every invoice after the USD amount. I`m adding it to every invoice my self.

Now i`m decided to try to make this automatically. So i contacted the payment processor, and he told me to add an additional filed in the DB where to store the bitcoin amount.

 

****************

In the callback/coinpayments.php file on lines 65-66 (right after the existing addInvoicePayment and logTransaction) is where you would store it with SQL. $amount2 has the amount of coins received and $currency2 has the coin (BTC, LTC, etc.)

****************

 

Here the coinpayments.php file:

 

**************************

<?php

 

# Required File Includes

include("../../../dbconnect.php");

include("../../../includes/functions.php");

include("../../../includes/gatewayfunctions.php");

include("../../../includes/invoicefunctions.php");

 

$gatewaymodule = "coinpayments"; # Enter your gateway module name here replacing template

$GATEWAY = getGatewayVariables($gatewaymodule);

if (!$GATEWAY["type"]) die("Module Not Activated"); # Checks gateway module is active before accepting callback

 

function coinpayments_error($msg) {

global $GATEWAY;

 

if (!empty($GATEWAY['coinpayments_email'])) {

$report = "AUTH User: ".$_SERVER['PHP_AUTH_USER']."\n";

$report .= "AUTH Pass: ".$_SERVER['PHP_AUTH_PW']."\n\n";

 

if ($msg) {

$report .= "Error Message: ".$msg."\n\n";

}

 

$report .= "POST Fields\n\n";

foreach ($_POST as $key => $value) {

$report .= $key . '=' . $value. "\n";

}

 

mail($GATEWAY['coinpayments_email'], "CoinPayments.net Invalid IPN", $report);

}

die($msg);

}

 

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $GATEWAY['coinpayments_merchant'] || $_SERVER['PHP_AUTH_PW'] != $GATEWAY['coinpayments_ipn_secret']) {

coinpayments_error("Invalid AUTH merchant ID/IPN secret!");

}

 

# Get Returned Variables - Adjust for Post Variable Names from your Gateway's Documentation

$ipn_type = $_POST["ipn_type"];

$merchant = $_POST["merchant"];

$status = $_POST["status"];

$status_text = $_POST["status_text"];

$invoiceid = $_POST["invoice"];

$transid = $_POST["txn_id"];

$amount1 = $_POST["amount1"];

$amount2 = $_POST["amount2"];

$currency1 = $_POST["currency1"];

$currency2 = $_POST["currency2"];

 

if ($ipn_type != "button") {

coinpayments_error("ipn_type != button");

}

if ($merchant != $GATEWAY['coinpayments_merchant']) {

coinpayments_error("Invalid merchant ID!");

}

if ($amount1 <= 0) {

coinpayments_error("Amount must be > 0!");

}

 

$invoiceid = checkCbInvoiceID($invoiceid,$GATEWAY["name"]); # Checks invoice ID is a valid invoice number or ends processing

 

checkCbTransID($transid); # Checks transaction number isn't already in the database and ends processing if it does

 

if ($status >= 100 || $status == 2 || $status == 1) {

addInvoicePayment($invoiceid,$transid,$amount1,0.00,$gatewaymodule); # Apply Payment to Invoice: invoiceid, transactionid, amount paid, fees, modulename

logTransaction($GATEWAY["name"],$_POST,$status_text.' (Original Amount: '.sprintf('%.8f', $amount1).' '.$currency1.') (Coins Paid: '.sprintf('%.8f', $amount2).' '.$currency2.') (Make sure original currency matches your WHMCS currency!)'); # Save to Gateway Log: name, data array, status

} else if ($status >= 0) {

logTransaction($GATEWAY["name"],$_POST,'Pending: '.$status_text);

} else {

logTransaction($GATEWAY["name"],$_POST,'Error: '.$status_text);

coinpayments_error($status_text);

}

 

?>

**************************

 

My question here are:

 

1) How to store the "$currency2" to a sql db

2) How to create the neded table

3) How to add it to the invoice template (but i think i can manage this when i get the point 1 and 2).

 

I will be very happy if there is some one who can help me with this.

 

Cheers,

Antoan

Link to comment
Share on other sites

Here the hint from coinpayments.net:

 

*************************

It would go in the callback/coinpayments.php file on lines 65-66 (right after the existing addInvoicePayment and logTransaction) is where you would store it with SQL. $amount2 has the amount of coins received and $currency2 has the coin (BTC, LTC, etc.)

 

You can try just using mysql_query or mysqli_query, but you may have to use WHMCS's internal database class however it works.

*************************

 

Can some one tell me which WHMCS db class i need to use?

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated