Question

I am trying to host forms for a recurly implementation and use PHP to create the signature. I have followed the docs, searched for examples and copied the code and tried every combination I can think of but I can not figure out what the issue is - on my PHP page the form appears but at the top I am seeing part of the PHP code instead of the code executing.

My code:

<?php
require_once('/lib/recurly.php');

// Required for the API
Recurly_Client::$subdomain = 'myactualsubdomain'
Recurly_Client::$apiKey = 'removedmyapiforsecurity';
Recurly_js::$privateKey = 'removedmyprivatekeyforsecurity';

$signature = Recurly_js::sign(array(
'account'=>array('account_code'=>'aaa1234588'), 
 'subscription' => array( 
 'plan_code' => 'innovator',
  'currency'=>'USD', 
    )));
?>

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Innovator Yearly Subscription</title>
<html>
  <head>
  <link rel="stylesheet" href="/css/recurly.css" type="text/css" />
<script src="/js/jquery.js"></script>
<script src="/js/recurly.js"></script>
    <script>
    $(function(){
      Recurly.config({
    subdomain: 'supportpay'
    , currency: 'USD' // GBP | CAD | EUR, etc...
  });

  Recurly.buildSubscriptionForm({
    target: '#recurly-subscribe',
    planCode: 'innovator',
    successURL: 'success.php',
    signature: '$signature',
distinguishContactFromBillingInfo: false,
collectCompany: false,
collectContact: true,
termsOfServiceURL: 'http://supportpay.com/contact/terms-of-use/',
acceptPaypal: false,
acceptedCards: ['mastercard',
                'discover',
                'american_express',
                'visa'],
  });

});
    </script>
    </head>
  <body>
    <h1>Subscribe to Plan</h1>
    <h2>Plan Code: Innovator - Yearly5</h2>
    <div id="recurly-subscribe">
    </div>
  </body>
</html>

When I use that code and run the php the browser the form / page render correctly except at the top there is this code

array('account_code'=>'aaa1234588'),'subscription' => array( 'plan_code' =>'innovator', 'currency'=>'USD', ))); ?> 

Can someone please shed some light on what I am doing wrong here?

Thank you!

Was it helpful?

Solution

Seems like you'd need to put the PHP variable inside a PHP tag:

Recurly.buildSubscriptionForm({
  target: '#recurly-subscribe',
  planCode: 'innovator',
  successURL: 'success.php',
  signature: '<?php print $signature ?>',
  distinguishContactFromBillingInfo: false,
  collectCompany: false,
  collectContact: true,
  termsOfServiceURL: 'http://supportpay.com/contact/terms-of-use/',
  acceptPaypal: false,
  acceptedCards: ['mastercard',
                  'discover',
                  'american_express',
                  'visa'],
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top