2

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

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

4

3 回答 3

9

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

// 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);

希望有帮助。

于 2015-06-27T06:15:09.127 回答
0
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使用您的公钥进行更新,该公钥可以在recurly api_keys中找到。

于 2020-06-24T10:55:33.447 回答
0

这是我在使用 RecurlyJS 的 Angular5/Typescript 环境中使用的函数。识别信用卡计费令牌与银行帐户之间的区别很重要。

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);
      });
    }
  });
}



于 2019-05-03T16:17:37.350 回答