PHP智能树网关API
请耐心等待,我正在尝试为我的wordpress预订系统创建一个Braintree网关,而不了解php。我已经从Braintree下载了php库文件,我用下面的代码实现了api连接和创建事务的区域。此代码是从另一个网关获取和调整的!这是一个好方法吗?这样行吗 我的代码PHP智能树网关API,php,wordpress,integration,payment-gateway,braintree,Php,Wordpress,Integration,Payment Gateway,Braintree,请耐心等待,我正在尝试为我的wordpress预订系统创建一个Braintree网关,而不了解php。我已经从Braintree下载了php库文件,我用下面的代码实现了api连接和创建事务的区域。此代码是从另一个网关获取和调整的!这是一个好方法吗?这样行吗 我的代码 $config = new Braintree\Configuration(); $config->environment($ap
$config = new Braintree\Configuration();
$config->environment($api_keys_merchant_id);
$config->merchantId(trim($api_keys_merchant_id));
$config->publicKey(trim($api_keys_public_key));
$config->privateKey(trim($api_keys_private_key));
$gateway = new Braintree\Gateway($config);
// Create transaction
$result = $gateway->transaction()->sale([
'amount' => $price,
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]]);
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
print_r("Validation errors: \n");
print_r($result->errors->deepAll());
} ```
就我个人而言,我不明白问题是什么,所以如果有,请说明。就调整而言,根据随附的代码示例,我想说:
- 不要引用未知变量或共享它们的上下文(例如:$parsedCredentials已初始化但未使用;还有什么是$request?)
- 在文件顶部使用“use”语句,而不是使用FQCN;这使得理解依赖项是什么以及代码做什么变得更容易
$gateway = new Braintree_Gateway([
'environment' => $api_keys_merchant_id,
'merchantId' => trim($api_keys_merchant_id),
'publicKey' => 'use_your_public_key',
'privateKey' => 'use_your_private_key'
]);
$result = $gateway->transaction()->sale([
'amount' => $price,
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]]);
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
print_r("Validation errors: \n");
print_r($result->errors->deepAll());
}