'',
'resourceUrl' => '',
'environment' => '',
'completion_html' => 'Thank you for signing up.',
'description_html' => '',
'show_vat_identifier' => 'false',
'show_price' => 'false',
'show_coupon' => 'false',
'show_credit_card' => 'true',
'show_bank_account' => 'false',
'show_header' => 'true',
'show_billing_agreement' => 'false',
'collect_customer' => 'true',
'collect_password' => 'false',
'custom_css' => '',
//'show_billing_address' => 'false',
'show_customer_address' => 'false',
'show_customer_phone' => 'false',
'require_customer_phone' => 'false',
'vat_on_e_services' => 'false',
'grecaptcha_sitekey' => '',
'show_tc_checkbox' => 'false',
'terms_and_conditions_html' => '',
'paypal_confirmurl' => '',
'paypal_cancelurl' => ''
), $atts ) );
switch (strtolower($environment))
{
case "test":
$environment_prefix = "test";
break;
case "itest":
$environment_prefix = "itest";
break;
default:
$environment_prefix = "";
}
if (empty($resourceUrl)) {
$resourceUrl = plugins_url('accumulus-subscription-commerce/public').'/';
}
$baseAjaxUrl = 'https://'.$environment_prefix.'ajax.accumulus.com';
$token = get_option('accumulus_'.$environment_prefix.'token');
if (empty($token)) {
_e("The Accumulus ".$environment." account is not connected. Please connect it under the Accumulus plugin settings before using the signup form.", "accumulus");
exit;
}
wp_enqueue_style('accumulus-ui-css', $resourceUrl.'/css/accumulus.ui.css');
if (!empty($custom_css)) {
wp_add_inline_style( 'accumulus-ui-css', $custom_css );
}
wp_enqueue_script('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js', array( 'jquery') );
wp_enqueue_script('jquery-validate', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js', array( 'jquery'));
wp_enqueue_script('jquery-validate-methods', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js', array( 'jquery'));
wp_enqueue_script('jquery-format-currency', $resourceUrl.'dependencies/jQueryFormatCurrencyPlugin/jquery.formatCurrency-1.4.0.js', array( 'jquery'));
wp_enqueue_script('jquery-format-currency-us', $resourceUrl.'dependencies/jQueryFormatCurrencyPlugin/i18n/jquery.formatCurrency.en-US.js', array( 'jquery'));
wp_enqueue_script('accumulus-core', $resourceUrl.'js/accumulus.core.js', array( 'jquery'));
wp_enqueue_script('accumulus-ui', $resourceUrl.'js/accumulus.ui.js', array( 'jquery', 'accumulus-core'));
wp_add_inline_script( 'accumulus-ui','
var Accumulus = {
resourcesUrl: "'.$resourceUrl.'",
serviceUrl: "'.$baseAjaxUrl.'/webapi",
global: {
localize: false,
defaultCountryCode: "USA"
}
};');
if (!empty($grecaptcha_sitekey)) {
wp_add_inline_script( 'accumulus-ui','
setTimeout(function()
{
var recaptchaScript = document.createElement("script");
recaptchaScript.src = "https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit";
document.body.appendChild(recaptchaScript);
}, 1000);
var onloadCallback = function() {
grecaptcha.render("acc-signup-recaptcha", {
"sitekey" : "'.$grecaptcha_sitekey.'"
});
};');
}
//echo 'Access Token: ' . $token->getToken() . "
";
//echo 'Already expired? ' . ($token->hasExpired() ? 'expired' : 'not expired') . "
";
//echo 'Refresh Token: ' . $token->getRefreshToken() . "
";
//echo 'Expired in: ' . $token->getExpires() . "
";
// refresh the oauth access token if it has expired
if ($token->hasExpired()) {
$client_id = get_option('accumulus_'.$environment_prefix.'client_id');
$client_secret = get_option('accumulus_'.$environment_prefix.'client_secret');
if ($client_id && $client_secret)
{
$provider = new League\OAuth2\Client\Provider\Accumulus([
"environmentPrefix" => $environment_prefix,
"clientId" => $client_id,
"clientSecret" => $client_secret,
"redirectUri" => admin_url("options-general.php?page=accumulus")
]);
} else {
_e("The Accumulus ".$environment." account is not connected. Please verify the client id and secret have been configured and the account connected under the Accumulus plugin settings before using the signup form.", "accumulus");
exit;
}
$token = $provider->getAccessToken('refresh_token', [
'refresh_token' => $token->getRefreshToken()
]);
update_option('accumulus_'.$environment_prefix.'token', $token, TRUE );
}
// obtain the Accumulus ajax token specifically for this plan code
$client = new GuzzleHttp\Client(['base_uri' => 'https://'.$environment_prefix.'webapi.accumulus.com']);
$headers = [
'Authorization' => 'Bearer ' . $token->getToken(),
'Accept' => 'application/json',
];
$response = $client->request('GET',
'/settings/hostedpages/signup/plans/'.$code.'/token', [
'headers' => $headers,
'exceptions' => false
]);
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case '200':
break;
case '404':
_e('Plan '.$code.' not found', 'accumulus');
exit;
break;
default:
_e('Cannot get plan '.$code.' ('.$statusCode.')', 'accumulus');
exit;
break;
}
$hostedPagesTokenRespone = json_decode($response->getBody());
ob_start();
?>