webpoint Posted May 20, 2015 Share Posted May 20, 2015 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! 0 Quote Link to comment Share on other sites More sharing options...
webpoint Posted May 22, 2015 Author Share Posted May 22, 2015 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"; 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 22, 2015 Share Posted May 22, 2015 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'] 0 Quote Link to comment Share on other sites More sharing options...
webpoint Posted May 22, 2015 Author Share Posted May 22, 2015 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! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.