我们将转移到Recurly进行计费,并计划使用recurly.js api在生产中生成计费令牌,但同时,在其他环境中很难进行测试。理想情况下,我希望能够将信用卡信息从我的服务器发送到Recurly端点,并返回一个计费令牌。
对我来说,最简单的方法是什么?如果答案是“使用recurly.js api”,我如何做到这一点?Recurly网站上唯一的示例是向服务器提交表单的网页。相反,我的服务器调用一个网页或其他端点,并在响应中获取令牌。
发布于 2015-06-27 06:15:09
我只是有这个问题。下面是我的解决方案,通过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);希望这能有所帮助。
发布于 2019-05-03 16:17:37
下面是我使用RecurlyJS在Angular5 5/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);
});
}
});
}发布于 2020-06-24 10:55:33
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,这可以在关键字上找到。
https://stackoverflow.com/questions/29706137
复制相似问题