Bitcoin WHMCS Module


SUBMITTED BY: Guest

DATE: May 6, 2013, 8:52 p.m.

FORMAT: PHP

SIZE: 4.4 kB

HITS: 1497

  1. <?php
  2. function bitcoin_config() {
  3. $configarray = array(
  4. "FriendlyName" => array("Type" => "System", "Value"=>"Bitcoin"),
  5. "username" => array("FriendlyName" => "RPC Username", "Type" => "text", "Size" => "20", ),
  6. "password" => array("FriendlyName" => "RPC Password", "Type" => "text", "Size" => "20", ),
  7. "host" => array("FriendlyName" => "RPC Hostname", "Type" => "text", "Size" => "20", ),
  8. "port" => array("FriendlyName" => "RPC Port", "Type" => "text", "Size" => "20", ),
  9. //"transmethod" => array("FriendlyName" => "Transaction Method", "Type" => "dropdown", "Options" => "Option1,Value2,Method3", ),
  10. //"instructions" => array("FriendlyName" => "Payment Instructions", "Type" => "textarea", "Rows" => "5", "Description" => "Do this then do that etc...", ),
  11. //"testmode" => array("FriendlyName" => "Test Mode", "Type" => "yesno", "Description" => "Tick this to test", ),
  12. );
  13. return $configarray;
  14. }
  15. function bitcoin_link($params) {
  16. # Gateway Specific Variables
  17. $u = $params['username'];
  18. $p = $params['password'];
  19. $h = $params['host'].':'.$params['port'];
  20. $rpc = 'http://'.$u.':'.$p.'@'.$h;
  21. # Invoice Variables
  22. $invoiceid = $params['invoiceid'];
  23. $amount = $params['amount']; # Format: ##.##
  24. $currency = $params['currency']; # Currency Code
  25. # Client Variables
  26. $firstname = $params['clientdetails']['firstname'];
  27. $lastname = $params['clientdetails']['lastname'];
  28. $email = $params['clientdetails']['email'];
  29. $address1 = $params['clientdetails']['address1'];
  30. $address2 = $params['clientdetails']['address2'];
  31. $city = $params['clientdetails']['city'];
  32. $state = $params['clientdetails']['state'];
  33. $postcode = $params['clientdetails']['postcode'];
  34. $country = $params['clientdetails']['country'];
  35. $phone = $params['clientdetails']['phonenumber'];
  36. # Build Bitcoin Information Here
  37. require_once 'bitcoin/jsonRPCClient.php';
  38. $bitcoin = new jsonRPCClient($rpc);
  39. if(!$bitcoin->getinfo()){
  40. die('could not connect to bitcoind');
  41. }
  42. $address = $bitcoin->getaccountaddress($params['clientdetails']['userid'].'-'.$invoiceid);
  43. # Enter your code submit to the gateway...
  44. $code = 'Send Payments to: '.$address.'<br /><img src="http://qrfree.kaywa.com/?l=1&s=4&d='.$address.'" alt="QRCode"/>';
  45. return $code;
  46. }
  47. function bitcoin_refund($params) {
  48. # Gateway Specific Variables
  49. $gatewayusername = $params['username'];
  50. $gatewaytestmode = $params['testmode'];
  51. # Invoice Variables
  52. $transid = $params['transid']; # Transaction ID of Original Payment
  53. $amount = $params['amount']; # Format: ##.##
  54. $currency = $params['currency']; # Currency Code
  55. # Client Variables
  56. $firstname = $params['clientdetails']['firstname'];
  57. $lastname = $params['clientdetails']['lastname'];
  58. $email = $params['clientdetails']['email'];
  59. $address1 = $params['clientdetails']['address1'];
  60. $address2 = $params['clientdetails']['address2'];
  61. $city = $params['clientdetails']['city'];
  62. $state = $params['clientdetails']['state'];
  63. $postcode = $params['clientdetails']['postcode'];
  64. $country = $params['clientdetails']['country'];
  65. $phone = $params['clientdetails']['phonenumber'];
  66. # Card Details
  67. $cardtype = $params['cardtype'];
  68. $cardnumber = $params['cardnum'];
  69. $cardexpiry = $params['cardexp']; # Format: MMYY
  70. $cardstart = $params['cardstart']; # Format: MMYY
  71. $cardissuenum = $params['cardissuenum'];
  72. # Perform Refund Here & Generate $results Array, eg:
  73. $results = array();
  74. $results["status"] = "success";
  75. $results["transid"] = "12345";
  76. # Return Results
  77. if ($results["status"]=="success") {
  78. return array("status"=>"success","transid"=>$results["transid"],"rawdata"=>$results);
  79. } elseif ($gatewayresult=="declined") {
  80. return array("status"=>"declined","rawdata"=>$results);
  81. } else {
  82. return array("status"=>"error","rawdata"=>$results);
  83. }
  84. }
  85. ?>

comments powered by Disqus