/** * Payment link. * * @param $params * @return string */ function checkoutjs_link($params) { $Api = CheckoutApi_Api::getApi(array('mode' => $params['modetype'])); $model = new model_methods_creditcard(); $paymentToken = $model->getPaymentToken($params); $publicKey = $params['publickey']; $email = $params['clientdetails']['email']; $amount = $params['amount']; $currencyCode = $params['currency']; $amountCents = $Api->valueToDecimal($amount, $currencyCode); $customerName = $params['clientdetails']['firstname'] . " " . $params['clientdetails']['lastname']; $returnUrl = $params['systemurl'] . '/modules/gateways/callback/checkoutjs_callback.php?cko-card-token='; $address1 = $params['clientdetails']['address1']; $address2 = $params['clientdetails']['address2']; $city = $params['clientdetails']['city']; $postcode = $params['clientdetails']['postcode']; $country = $params['clientdetails']['countrycode']; $state = $params['clientdetails']['state']; $logoUrl = $params['logoUrl']; $themeColor = $params['themeColor']; $iconColor = $params['iconColor']; $buttonColor = $params['buttonColor']; $useCurrencyCode = $params['useCurrencyCode'] ? 'true' : 'false'; $title = $params['title']; $widgetColor = $params['widgetColor']; $buttonLabelColor = $params['buttonLabelColor']; $formButtonColor = $params['formButtonColor']; $formButtonColorLabel = $params['formButtonColorLabel']; $overlayShade = $params['overlayShade']; $overlayOpacity = $params['overlayOpacity']; $showMobileIcons = $params['showMobileIcons']; $widgetIconSize = $params['widgetIconSize']; $url = $params['modetype'] == 'Live' ? model_methods_creditcard::CHECKOUT_NON_PCI_JS_URL_LIVE : model_methods_creditcard::CHECKOUT_NON_PCI_JS_URL_SANDBOX; $errorMessage = getErrorMessage(); $code = @"\n <div style='width:150px; margin:0 auto;'>\n <script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>\n <script src={$url}></script>\n <script>\n Checkout.render({\n debugMode : true,\n publicKey : '{$publicKey}',\n paymentToken : '{$paymentToken}',\n customerEmail : '{$email}',\n customerName : '{$customerName}',\n value : '{$amountCents}',\n currency : '{$currencyCode}',\n paymentMode : 'card',\n forceRedirect : false,\n //payButtonSelector : '#payNow',\n cardFormMode : 'cardTokenisation',\n billingDetails: {\n 'addressLine1' : '{$address1}',\n 'addressLine2' : '{$address2}',\n 'postcode' : '{$postcode}',\n 'country' : '{$country}',\n 'city' : '{$city}',\n 'state' : '{$state}'\n },\n logoUrl :'{$logoUrl}',\n renderMode : 1,\n themeColor :'{$themeColor}',\n buttonColor :'{$buttonColor}',\n iconColor :'{$iconColor}',\n useCurrencyCode :'{$useCurrencyCode}',\n title :'{$title}',\n widgetColor :'{$widgetColor}',\n buttonLabelColor :'{$buttonLabelColor}',\n styling : {\n formButtonColor : '{$formButtonColor}',\n formButtonColorLabel : '{$formButtonColorLabel}',\n overlayShade : '{$overlayShade}',\n overlayOpacity : '{$overlayOpacity}',\n showMobileIcons : '{$showMobileIcons}',\n widgetIconSize : '{$widgetIconSize}'\n },\n ready: function (event) {\n if(document.getElementById('whmcsorderfrm')){\n document.getElementsByClassName('alert')[0].style.visibility='hidden';\n document.getElementsByClassName('textcenter')[0].style.visibility='hidden';\n }\n },\n widgetRendered: function (){\n if(document.getElementById('whmcsorderfrm')){\n //document.getElementById('cko-widget').style.visibility='hidden';\n }\n },\n cardTokenised: function(event) {\n if(document.getElementById('whmcsorderfrm')){\n document.getElementById('cko-widget').style.visibility='hidden';\n document.getElementsByClassName('textcenter')[0].style.visibility='visible';\n }\n window.location.href = '{$returnUrl}'+event.data.cardToken;\n }\n });\n </script>\n </div>\n "; if ($errorMessage) { $code .= "<div><p style='color:red;'>{$errorMessage}</p></div>"; } return $code; }
$currency = $_SESSION['favcolor']['postedParam']['currency']; $config['authorization'] = $GATEWAY['secretkey']; $config['postedParam'] = array('trackId' => $invoiceId, 'value' => $_SESSION['favcolor']['postedParam']['value'], "chargeMode" => model_methods_creditcard::CHECKOUT_NON_PCI_CHARGE_MODE_NON_3D, 'currency' => $currency, 'autoCapture' => $_SESSION['favcolor']['postedParam']['autoCapture'], 'autoCapTime' => $_SESSION['favcolor']['postedParam']['autoCapTime'], 'cardToken' => $_REQUEST['cko-card-token'], 'email' => $_SESSION['favcolor']['postedParam']['email'], 'customerName' => $_SESSION['favcolor']['postedParam']['custName'], 'metadata' => $_SESSION['favcolor']['postedParam']['metadata']); $respondCharge = $Api->createCharge($config); $returnUrl = $OtherVariables["systemurl"] . "/viewinvoice.php?id=" . $invoiceId; if ($Api->getExceptionState()->hasError()) { $message = 'Your payment was not completed.' . $Api->getExceptionState()->getErrorMessage() . ' and try again or contact customer support.'; logTransaction($GATEWAY["name"], $message, "Unsuccessful"); $_SESSION['checkout_error'] = true; $_SESSION['checkout_error_message'] = $message; header("Location:" . $returnUrl); exit; } $chargeId = is_object($respondCharge) ? $respondCharge->getId() : null; $redirectUrl = is_object($respondCharge) ? $respondCharge->getRedirectUrl() : null; if (!$respondCharge->isValid() || !model_methods_creditcard::responseValidation($respondCharge)) { $transactionMessage = !empty($chargeId) && empty($redirectUrl) ? ", transaction id - {$chargeId}" : ''; logTransaction($GATEWAY["name"], "Your payment was not completed. Response is invalid for trackId - {$invoiceId}{$transactionMessage}. Action - authorize. Try again or contact customer support.", "Unsuccessful"); $_SESSION['checkout_error'] = true; $_SESSION['checkout_error_message'] = 'Please check you card details and try again. Thank you'; header("Location:" . $returnUrl); exit; } if ($redirectUrl) { $_SESSION['checkout_payment_token']['invoice_id'] = $invoiceId; $_SESSION['checkout_payment_token']['token'] = $respondCharge->getId(); header("Location:" . $redirectUrl); exit; } $cardId = $respondCharge->getCard()->getId(); $amount = $Api->decimalToValue($respondCharge->getValue(), $currency);