Recurly.js - PHP客户端 - 数字签名

时间:2014-02-13 10:37:57

标签: javascript php signature recurly

我正在尝试为重复实现托管表单,并使用PHP创建签名。我已经按照文档,搜索了示例并复制了代码并尝试了我能想到的每一个组合,但我无法弄清楚问题是什么 - 在我的PHP页面上显示的是表单,但在顶部我看到了PHP的一部分代码而不是代码执行。

我的代码:

<?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>

当我使用该代码并运行php浏览器时,表单/页面正确呈现,除了在顶部有这个代码

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

有人可以说明我在这里做错了吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

好像你需要将PHP变量放在PHP标记中:

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'],
});