From 7c084d9ef52b349b77865d4f6556c1b6ec14acdd Mon Sep 17 00:00:00 2001 From: dzung2t Date: Fri, 18 Sep 2015 14:48:20 +0700 Subject: [PATCH] Add Brick support --- src/brickccform.php | 109 +++++++++++ src/images/paymentwall/brick_logo.png | Bin 0 -> 4092 bytes src/images/paymentwall/paymentwall_logo.png | Bin 0 -> 1288 bytes src/modules/gateways/brick.php | 50 +++++ src/modules/gateways/paymentwall.php | 16 +- src/modules/gateways/paymentwall/index.html | 0 .../gateways/paymentwall/templates/ccform.tpl | 176 ++++++++++++++++++ .../gateways/paymentwall/templates/widget.tpl | 9 + src/paymentwallwidget.php | 25 +++ 9 files changed, 380 insertions(+), 5 deletions(-) create mode 100644 src/brickccform.php create mode 100644 src/images/paymentwall/brick_logo.png create mode 100644 src/images/paymentwall/paymentwall_logo.png create mode 100644 src/modules/gateways/brick.php create mode 100644 src/modules/gateways/paymentwall/index.html create mode 100644 src/modules/gateways/paymentwall/templates/ccform.tpl create mode 100644 src/modules/gateways/paymentwall/templates/widget.tpl create mode 100644 src/paymentwallwidget.php diff --git a/src/brickccform.php b/src/brickccform.php new file mode 100644 index 0000000..fb5e978 --- /dev/null +++ b/src/brickccform.php @@ -0,0 +1,109 @@ +load_function('gateway'); +$whmcs->load_function('clientarea'); +$whmcs->load_function('invoice'); + +$gateway = getGatewayVariables("brick"); + +$whmcsVer = substr($CONFIG['Version'], 0, 1); +if ($whmcsVer <= 5) { + $gateways = new WHMCS_Gateways(); +} else { + $gateways = new WHMCS\Gateways(); +} +$publicKey = $gateway['isTest'] ? $gateway['publicTestKey'] : $gateway['publicKey']; +Paymentwall_Config::getInstance()->set(array( + 'api_type' => Paymentwall_Config::API_GOODS, + 'public_key' => $publicKey, // available in your Paymentwall merchant area + 'private_key' => $gateway['isTest'] ? $gateway['privateTestKey'] : $gateway['privateKey'] // available in your Paymentwall merchant area +)); + +$pagetitle = $_LANG['clientareatitle'] . " - Pay via Brick (Powered by Paymentwall)"; +initialiseClientArea($pagetitle, '', 'Pay via Brick'); + +# Check login status +if ($_SESSION['uid'] && isset($_POST['data']) && $post = json_decode(decrypt($_POST['data']), true)) { + + $smartyvalues = array_merge($smartyvalues, $post); + $smartyvalues["data"] = $_POST['data']; + $smartyvalues["whmcsVer"] = $whmcsVer; + $smartyvalues["publicKey"] = $publicKey; + $smartyvalues["processingerror"] = ''; + $smartyvalues["success"] = false; + + if ($_POST['frominvoice'] == "true" || $_POST['fromCCForm'] == 'true') { + + if ($whmcsVer <= 5) { + $invoice = new WHMCS_Invoice(); + } else { + $invoice = new WHMCS\Invoice(); + } + $invoice->setID($_POST["invoiceid"]); + $invoiceData = $invoice->getOutput(); + + // Prepare form data + $smartyvalues["client"] = $invoiceData['clientsdetails']; + $smartyvalues['months'] = $gateways->getCCDateMonths(); + $smartyvalues['years'] = $gateways->getCCExpiryDateYears(); + $smartyvalues['invoice'] = $invoiceData; + $smartyvalues['invoiceItems'] = $invoice->getLineItems(); + + if ($_POST['fromCCForm'] == 'true') { # Check form submit & capture payment + + $cardInfo = array( + 'email' => $invoiceData['clientsdetails']['email'], + 'amount' => $post['amount'], + 'currency' => $post["currency"], + 'token' => $_POST['brick_token'], + 'fingerprint' => $_POST['brick_fingerprint'], + 'description' => $invoiceData['pagetitle'] + ); + + $charge = new Paymentwall_Charge(); + $charge->create(array_merge( + $cardInfo, + brick_get_user_profile_data($invoiceData) + )); + $response = $charge->getPublicData(); + + if ($charge->isSuccessful()) { + if ($charge->isCaptured()) { + addInvoicePayment($_POST["invoiceid"], $charge->getId(), null, null, 'brick'); + } elseif ($charge->isUnderReview()) { + // decide on risk charge + } + $smartyvalues["success"] = true; + } else { + $error = json_decode($response, true); + $smartyvalues["processingerror"] = '
  • ' . $error['error']['message'] . '
  • '; + } + + } + + } else { // User is logged in but they shouldn't be here (i.e. they weren't here from an invoice) + header("Location: " . $CONFIG['SystemURL'] . "/clientarea.php?action=details"); + } +} else { + header("Location: " . $CONFIG['SystemURL'] . "/"); +} + +outputClientArea("/modules/gateways/paymentwall/templates/ccform.tpl"); + +function brick_get_user_profile_data($params) +{ + return array( + 'customer[city]' => $params['clientsdetails']['city'], + 'customer[state]' => $params['clientsdetails']['fullstate'], + 'customer[address]' => $params['clientsdetails']['address1'], + 'customer[country]' => $params['clientsdetails']['countrycode'], + 'customer[zip]' => $params['clientsdetails']['postcode'], + 'customer[username]' => $params['clientsdetails']['userid'] ? $params['clientsdetails']['userid'] : $params['clientsdetails']['email'], + 'customer[firstname]' => $params['clientsdetails']['firstname'], + 'customer[lastname]' => $params['clientsdetails']['lastname'], + ); +} \ No newline at end of file diff --git a/src/images/paymentwall/brick_logo.png b/src/images/paymentwall/brick_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..77ee32a9a0176299cdefc0822e1223d4df9e8935 GIT binary patch literal 4092 zcmaJ^c{r5q+m=F>n6dB1n6l59v1PJm$jFFkD$A5@24k5SV`L~A%4?7<%a9}@TZ*z| zi3*`ei6W$UBeGVavGg17@9q7*Kfd>Sj^lam`@W9rJg@Uw{AREp ze?MSuG#bGdiACA|9gBN11N+nIR3r=*9v%)2*N0MQelWO+i3v;(0Ye~kxgNTq5oEd- zLzf(?_L~7k4E3RrsB{vA4BBDz@}`8*&A?ox|4kv7`VTER^zSlp3kG9&QDJbX-cCxt z9Wj{y-!(Y+AMa2)miRw<|4-sjTm+Q}!xBR&VKg6Z<9yY2LQ#>{G@=)sLc>ugLBFf$ z^_@5eYz}tZB6mA`R>&X;^tN24g*u}Nh)4b zbPKxYR?jOQ7h`(ZEwXLcaXhjWqLI~~B-(ZLzIsY)1ZP-PUsI)~o%$xDKn|BtZWNT#HM!iCVrH=~AsdbfhJ*{&s1YClj z5dfbYka@r2hE!8xd+JITORNBIP28MyDde!D)-vd+0R0h+M`UW(oxXW9$9#+ zpTqe)Vl2p^>9mx%O-SX)@VY(P`EmFaEj~2Z_qM=retk@u-Mtzz>Z?uBV;25hWM#XH zG2)ySMbulf zfotVE3fuZfxahoL3eV;S#K#?zQ#Bkit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tO`E}y+Q8V$3(Nhga7rq}{XXK{$N=Z25aaP9K1*}f#NTPV*W?vzE zs2uVgb$L2kf3y3@dwk-}ci@vw?LSnr%8N?3gPZyt3jat8K##u`WQAp3Ph6KMY3mxi zIN;!=OI{2!^_DI%q(;41ioz-WcywLQXWde6+{dh7IMOzHJWpQwHUa&@aG`)xD**JgE7| zilZM_2lIo>E$PI>OXSOjlV9d%yS_<-yiFxDFn3B-(*1QO`&mPK-!=$UJFk711~sa! zah74=WwB(*-3C`GT4q!|?#FXJJB17ji|#KD=uexJ#L9Qa-9hOTB1Yr24|r$!eKEP} z!WT{+uhoKU{>(4DseU_wB4J?}*d(4#&?~!@ZuHw-k>%#tSw)Ua8b%DY^2p*h=xnpAjW9CZiaN`Ai`$N?q zT~4d)A0Ty)-@f&c8AE^PLE6~&so~0i9Z~6)!Iwf)E9f$SZ&PY4%(XQs)7)yDqmJJ9 z+@#Z|%h(zJbU=FVsqnk^_R>7X}WI7qjxh0v3oj)qBe;@ zzNO1)$9&WhUkd5uIA*JBX5jPe_B|U87~L9C|8gRr@2PXfEhs4?XZaFnuT?6XREq=- z`C0e<485QyH<#Ca*Zttv+VA|Oz?jWe5r(jZI6M_lH@&oh8gQ2!P$+lEqK`+GOyrq^ z)L=%?dJ4$C<4lmlTpHH5&fr&3&7B`2N0b$0HV!T^`PsU>kjWm%gXRZIsfxzPl2CS* ze6rh8GD;A=5Kz~Y<0`v0|NTP~FK7Px&g~Sa!V)gFmlrY$yLrH3rMVuB9C+Qr9!&moEC;t{kE@!Zt#u0VruxIRl01}=TuK)l5 literal 0 HcmV?d00001 diff --git a/src/images/paymentwall/paymentwall_logo.png b/src/images/paymentwall/paymentwall_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..37fb48ccef4d878cd57baa36c6408f532fd75917 GIT binary patch literal 1288 zcmV+j1^4=iP)2yED7nJ>4UUJ_tU`Ndytayl5aG5 zlfZe92QQZsPai_?@K!J)YQ#Xqzd)i<@aIhKjQKHlyNOjZ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" => "System", "Value" => "Brick (Powered by Paymentwall)"), + "publicKey" => array("FriendlyName" => "Public Key", "Type" => "text", "Size" => "20",), + "privateKey" => array("FriendlyName" => "Private Key", "Type" => "text", "Size" => "20",), + "publicTestKey" => array("FriendlyName" => "Public Test Key", "Type" => "text", "Size" => "20",), + "privateTestKey" => array("FriendlyName" => "Private Test Key", "Type" => "text", "Size" => "20",), + "isTest" => array("FriendlyName" => "Is Test", "Type" => "yesno", "Size" => "5",), + ); + return $configarray; +} + +function init_brick_config($params) +{ + require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php'); + Paymentwall_Config::getInstance()->set(array( + 'api_type' => Paymentwall_Config::API_GOODS, + 'public_key' => $params['isTest'] ? $params['publicTestKey'] : $params['publicKey'], // available in your Paymentwall merchant area + 'private_key' => $params['isTest'] ? $params['privateTestKey'] : $params['privateKey'] // available in your Paymentwall merchant area + )); +} + +function brick_link($params) +{ + global $CONFIG; + + init_brick_config($params); + # Invoice Variables + $invoiceid = $params['invoiceid']; + + # Enter your code submit to the gateway... + $code = '
    + + + + +
    '; + return $code; +} diff --git a/src/modules/gateways/paymentwall.php b/src/modules/gateways/paymentwall.php index 5979d7a..80d7bb1 100644 --- a/src/modules/gateways/paymentwall.php +++ b/src/modules/gateways/paymentwall.php @@ -15,7 +15,7 @@ function paymentwall_config() function init_paymentwall_config($params) { - require_once(getcwd() . '/includes/api/paymentwall_api/lib/paymentwall.php'); + require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set(array( 'api_type' => Paymentwall_Config::API_GOODS, 'public_key' => $params['appKey'], // available in your Paymentwall merchant area @@ -47,14 +47,20 @@ function paymentwall_link($params) get_user_profile_data($params) ) ); - $widgetUrl = $widget->getUrl(); - $code = '
    Paymentwall logo
    '; + $widgetUrl = $params['systemurl'] . '/paymentwallwidget.php'; + $code = '
    + + +
    '; return $code; } -function get_user_profile_data($params){ - +function get_user_profile_data($params) +{ return array( 'customer[city]' => $params['clientdetails']['city'], 'customer[state]' => $params['clientdetails']['fullstate'], diff --git a/src/modules/gateways/paymentwall/index.html b/src/modules/gateways/paymentwall/index.html new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/gateways/paymentwall/templates/ccform.tpl b/src/modules/gateways/paymentwall/templates/ccform.tpl new file mode 100644 index 0000000..3a7fa87 --- /dev/null +++ b/src/modules/gateways/paymentwall/templates/ccform.tpl @@ -0,0 +1,176 @@ +{if $whmcsVer <= 5} + {include file="$template/pageheader.tpl" showbreadcrumb=false} +{else} + {include file="$template/includes/pageheader.tpl" showbreadcrumb=false} +{/if} + +{if $success != true} +
    + The following errors occurred: +
      + {$processingerror} +
    +
    +
    +
    +
    +

    {$LANG.invoicenumber}{$invoiceid}

    + +
    + + + + + + {foreach $invoiceItems as $item} + + + + + {/foreach} + + + + + {if $invoice.taxrate} + + + + + {/if} + {if $invoice.taxrate2} + + + + + {/if} + + + + + + + + +
    {$LANG.invoicesdescription}{$LANG.invoicesamount}
    {$item.description}{$item.amount}
    {$LANG.invoicessubtotal}{$invoice.subtotal}
    {$invoice.taxrate}% {$invoice.taxname}{$invoice.tax}
    {$invoice.taxrate2}% {$invoice.taxname2}{$invoice.tax2}
    {$LANG.invoicescredit}{$invoice.credit}
    {$LANG.invoicestotaldue}{$invoice.total}
    +
    +
    +
    +
    +
    +

    Credit Card Details

    +
    +
    + + +
    + +
    +
    +
    + + +
    + + +
    +
    +
    + + +
    + + +
    +
    +
    +
    + + + + Cancel Payment +
    +
    +
    + + + +
    + + +
    +{/if} +{if $success == true} +
    +

    Success

    +

    Your credit card payment was successful.

    +

    Click + here to view your paid invoice.

    +
    +{/if} +
    + +
    +
    +
    + \ No newline at end of file diff --git a/src/modules/gateways/paymentwall/templates/widget.tpl b/src/modules/gateways/paymentwall/templates/widget.tpl new file mode 100644 index 0000000..f97aed8 --- /dev/null +++ b/src/modules/gateways/paymentwall/templates/widget.tpl @@ -0,0 +1,9 @@ +{if $whmcsVer <= 5} + {include file="$template/pageheader.tpl" showbreadcrumb=false} +{else} + {include file="$template/includes/pageheader.tpl" showbreadcrumb=false} +{/if} + +
    + {$iframe} +
    \ No newline at end of file diff --git a/src/paymentwallwidget.php b/src/paymentwallwidget.php new file mode 100644 index 0000000..fde450c --- /dev/null +++ b/src/paymentwallwidget.php @@ -0,0 +1,25 @@ +load_function('clientarea'); + +$pagetitle = $_LANG['clientareatitle'] . " - Pay via Paymentwall"; +initialiseClientArea($pagetitle, '', 'Pay via Paymentwall'); + +$whmcsVer = substr($CONFIG['Version'], 0, 1); +$smartyvalues["whmcsVer"] = $whmcsVer; + +# Check login status +if ($_SESSION['uid'] && isset($_POST['data']) && $iframe = decrypt($_POST['data'])) { + if ($iframe) { + $smartyvalues['iframe'] = $iframe; + } else { // User is logged in but they shouldn't be here (i.e. they weren't here from an invoice) + header("Location: " . $CONFIG['SystemURL'] . "/clientarea.php?action=details"); + } +} else { + header("Location: " . $CONFIG['SystemURL'] . "/"); +} + +outputClientArea('/modules/gateways/paymentwall/templates/widget.tpl');