php - PHP Braintree 网关 API
问题描述
请耐心等待,我正在尝试为我的 wordpress 预订系统创建一个 Braintree 网关,但不了解 php。我已经从 Braintree 下载了 php 库文件,并使用下面的代码实现了 api 连接区域和创建事务。此代码是从另一个网关获取和调整的!这是一个很好的使用方法吗?这行得通吗?
我的代码
$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());
} ```
解决方案
$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());
}
推荐阅读
- java - 使用 Keycloak 作为身份代理和 Okta 作为身份提供者的 Saml 设置不起作用
- python - 使用 create_task 创建的从未等待的任务似乎打破了取消子任务的预期
- react-native - 警告:尝试呈现
上 这已经在呈现 - javascript - 如何在主题js中放置cookie同意?
- ios - 为什么默认的 UIWindowSceneDelegate 类继承自 UIResponder?
- c++ - 显示字符串的集合和子集
- python - 如何在 AWS CDK 中创建自定义资源
- go - 将值分配给变量,同时将其传递给 Go 中的函数
- javascript - 如何将 JSON 数据显示为矩阵(如 SSRS 中的矩阵)?
- python-3.x - 没有名为“bayesian_bandit”的模块