首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有一种不使用recurly.js从Recurly获得计费令牌的方法?

有没有一种不使用recurly.js从Recurly获得计费令牌的方法?
EN

Stack Overflow用户
提问于 2015-04-17 17:47:09
回答 3查看 2K关注 0票数 2

我们将转移到Recurly进行计费,并计划使用recurly.js api在生产中生成计费令牌,但同时,在其他环境中很难进行测试。理想情况下,我希望能够将信用卡信息从我的服务器发送到Recurly端点,并返回一个计费令牌。

对我来说,最简单的方法是什么?如果答案是“使用recurly.js api”,我如何做到这一点?Recurly网站上唯一的示例是向服务器提交表单的网页。相反,我的服务器调用一个网页或其他端点,并在响应中获取令牌。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-06-27 06:15:09

我只是有这个问题。下面是我的解决方案,通过curl (在PHP中)从recurly.js使用的URL收集测试令牌。

代码语言:javascript
复制
// Billing token generator helper
public function getBillingToken($data) {
    $data['version'] = '3.1.0';
    $data['key'] = $this->recurlyPublicKey;

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://api.recurly.com/js/v1/token?".http_build_query($data)); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0"); 
    $result = curl_exec($ch);
    curl_close($ch);
    $reply = json_decode($result, true);
    return $reply['id'];
}

$billingData = array(
    'first_name' => 'John',
    'last_name' => 'jones',
    'number' => '4111111111111111',
    'month' => '12',
    'year' => '2016',
    'cvv' => '123',
    'address1' => 'Some address',
    'country' => 'AU',
    'city' => 'Melbourne',
    'state' => 'Victoria',
    'postal_code' => '3001',
);

$token = getBillingToken($billingData);

希望这能有所帮助。

票数 9
EN

Stack Overflow用户

发布于 2019-05-03 16:17:37

下面是我使用RecurlyJS在Angular5 5/Typescript环境中使用的函数。识别信用卡和银行账户的记帐令牌之间的区别是很重要的。

代码语言:javascript
复制
private getRecurlyToken(locationId): Promise<string> {
  return new Promise<string>((resolve, reject) => {
    let recurly = window['recurly'];
    recurly.configure({publicKey: Config['RECURLY_PUBLIC_KEY'], parent: false});
    if(this.paymentMethod.value === 'card') {
      recurly.token({
        number: this.cardInfoForm.value.cardNumber,
        month: this.cardInfoForm.value.expMonth,
        year: this.cardInfoForm.value.expYear,
        first_name: this.cardInfoForm.value.firstName,
        last_name: this.cardInfoForm.value.lastName,
        cvv: this.cardInfoForm.value.cardCVC,
        address1: this.billingAddressForm.value.address1,
        address2: this.billingAddressForm.value.address2,
        city: this.billingAddressForm.value.city,
        state: this.billingAddressForm.value.state,
        postal_code: this.billingAddressForm.value.postalCode,
        country: 'US',
      }, (error, token) => {
        if(error && error.code === 'validation') { return reject(this.validationError('credit card', error)); }
        else if(error) { return reject(error); }
        resolve(token.id);
      });
    } else {
      recurly.bankAccount.token({
        name_on_account: this.bankInfoForm.value.nameOnAccount,
        account_number: this.bankInfoForm.value.accountNumber,
        account_number_confirmation: this.bankInfoForm.value.accountConfirmation,
        routing_number: this.bankInfoForm.value.routingNumber,
        account_type: this.bankInfoForm.value.accountType,
        address1: this.billingAddressForm.value.address1,
        address2: this.billingAddressForm.value.address2,
        city: this.billingAddressForm.value.city,
        state: this.billingAddressForm.value.state,
        postal_code: this.billingAddressForm.value.postalCode,
        country: 'US',
      }, (error, token) => {
        if(error && error.code === 'validation') { return reject(this.validationError('bank', error)); }
        else if(error) { return reject(error); }
        resolve(token.id);
      });
    }
  });
}
票数 0
EN

Stack Overflow用户

发布于 2020-06-24 10:55:33

代码语言:javascript
复制
const toUrlEncoded = obj => Object.keys(obj).map(k => encodeURIComponent(k) + '=' + encodeURIComponent(obj[k])).join('&');


const data = toUrlEncoded({
          key: 'Recurly_Public_Token_Key',
          version: '4.12.0',
          first_name: 'Vasyl',
          last_name: 'Pupkin',
          number: '4111111111111111',
          year: '2022',
          month: '12',
          cvv: '999',
          address1: 'Freedom st.',
          country: 'US',
          city: 'NY',
          state: 'NY',
          postal_code: '51200',
});

await axios({
    url: 'https://api.recurly.com/js/v1/token',
    method: 'post',
    data,
});

不要忘记用您的公钥更新Recurly_Public_Token_Key,这可以在关键字上找到。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29706137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档