Jump to content

Modifying payment calback.php script to send notification mails


webpoint

Recommended Posts

Hi all,

 

We switched to a new payment processor - spectrocoin.

But there script don`t send out notification when a payment is made.

So we modified the callback script like this:

 

###########################
<?php
# Required File Includes
include '../../../dbconnect.php';
include '../../../includes/functions.php';
include '../../../includes/gatewayfunctions.php';
include '../../../includes/invoicefunctions.php';
require_once '../spectrocoin/lib/SCMerchantClient/SCMerchantClient.php';

$gatewaymodule = "spectrocoin";
$GATEWAY = getGatewayVariables($gatewaymodule);

if (!$GATEWAY["type"]) {
logTransaction($GATEWAY["name"], $_POST, 'Not activated');
error_log('Spectrocoin module not activated');
exit("Spectrocoin module not activated");
}

$privateKey = __DIR__ . '/../spectrocoin/keys/private';

if (!file_exists($privateKey) || !is_file($privateKey)) {
error_log('SpectroCoin. No private key file found');
exit('No private key file found');
}

$merchantId = $GATEWAY['merchantId'];
$appId = $GATEWAY['appId'];
$receiveCurrency = $GATEWAY['receive_currency'];

$request = $_REQUEST;
$client =  new SCMerchantClient($privateKey, '', $merchantId, $appId);
$callback = $client->parseCreateOrderCallback($request);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($client->validateCreateOrderCallback($callback)) {
	if ($callback->getReceiveCurrency() != $receiveCurrency) {
		error_log('SpectroCoin error. Currencies does not match in callback');
		exit('SpectroCoin error. Currencies does not match in callback');
	}
	if (!isset($_GET['invoice_id'])) {
		error_log('SpectroCoin error. invoice_id is not provided');
		exit('SpectroCoin error. invoice_id is not provided');
	}
	$invoiceId = intval($_GET['invoice_id']);
	$status = $callback->getStatus();

	switch ($status) {
		case OrderStatusEnum::$Test:
		case OrderStatusEnum::$New:
			//update amount of bitcoints
			$table = "tblinvoices";
			$update = array("amount2" => $callback->getReceivedAmount());
			$where = array("id"=>$invoiceId);
			update_query($table, $update, $where);
		case OrderStatusEnum::$Pending:
		case OrderStatusEnum::$Expired:
		case OrderStatusEnum::$Failed:

//Send mail when payment is submitted	

>> $command = "sendadminemail";
>>  $adminuser = "adminus";
>> $values["type"] = "system";
>> $values["customsubject"] = "Payment Submitted";
>> $values["custommessage"] = "$client_name ,Invoice: $invoiceId";


>> $results = localAPI($command,$values,$adminuser);

			break;
		case OrderStatusEnum::$Paid:
			$invoiceId = checkCbInvoiceID($invoiceId, $GATEWAY["name"]);
			$transId = "SC".$callback->getOrderRequestId();
			checkCbTransID($transId);
			$result = select_query('tblinvoices', 'total', array('id'=>$invoiceId));
			$data = mysql_fetch_array($result);
			$amount = $data['total'];
			$fee = 0;
			addInvoicePayment($invoiceId, $transId, $amount, $fee, $gatewaymodule);
			logActivity("Received SpectroCoin paid callback for invoice #$invoiceId. Transaction #$transId: Received amount: $amount $receiveCurrency, Paid amount: " . $callback->getReceivedAmount() . " ". $callback->getPayCurrency());

//Send mail when payment is DONE

>>  $command = "sendadminemail";
>>  $adminuser = "admin";
>>  $values["type"] = "system";
>>  $values["customsubject"] = "Payment!!!";
>> $values["custommessage"] = "Invoice: $invoiceId , Amount: $amount";


$results = localAPI($command,$values,$adminuser);

			break;
		default:
			error_log('SpectroCoin callback error. Unknown order status: ' . $status);
			exit('Unknown order status: ' . $status);
	}
	echo '*ok*';


} else {
	error_log('SpectroCoin error. Invalid callback');
	exit('SpectroCoin error. Invalid callback');
}
} else {
header('Location: /');
}
###################################################

Check this code:
>> $command = "sendadminemail";
>>  $adminuser = "admin";
>> $values["type"] = "system";
>> $values["customsubject"] = "Payment Submitted";
>> $values["custommessage"] = "$client_name ,Invoice: $invoiceId";

 

This sends out mails when a payment is submitted, and when a payment is paid.

Problem is, that we need to get the client name who did the payment per mail and the invoice ID.

This sends out the mail, but we get only invoice ID.

How to accomplish to get the Client name to?

 

Appreciate if some one can give us hint here:)

 

Cheers!

Link to comment
Share on other sites

Got this resolution from the payment processor, but it does not pull out anything:

$userId = select_query('tblinvoices', 'userid', array('id'=>$invoiceId));
$clientEmail = select_query('tblclients', 'email', array('id'=>$userId));	

$command = "sendadminemail";
$adminuser = "adminus";
$values["type"] = "system";
$values["customsubject"] = "Payment!!!";
$values["custommessage"] = "Invoice: $invoiceId , Amount: $amount";

Link to comment
Share on other sites

if you need to get client email it should be something like this

 

$userID = select_query('tblinvoices', 'userid', array('id'=>$invoiceId));
$userID = mysql_fetch_assoc($userID);
$clientEmail = select_query('tblclients', 'email', array('id'=>$userID['userid']));
$clientEmail = mysql_fetch_assoc($clientEmail);

// Client Email Variable
// $clientEmail['email']

Link to comment
Share on other sites

if you need to get client email it should be something like this

 

$userID = select_query('tblinvoices', 'userid', array('id'=>$invoiceId));
$userID = mysql_fetch_assoc($userID);
$clientEmail = select_query('tblclients', 'email', array('id'=>$userID['userid']));
$clientEmail = mysql_fetch_assoc($clientEmail);

// Client Email Variable
// $clientEmail['email']

 

Perfect:))

This is working!

 

Many thanks sentq!

Link to comment
Share on other sites

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