我正在将Gravity Form与Braintree加载项一起使用,我想做的是通过信用卡付款添加订阅。当我转到表格->结算-> braintree时,在交易类型->产品和服务中只有一个选项没有订阅选项,我从这里-> https://developers.braintreepayments.com/javascript+php/guides/recurring-billing
搜索但是它对我不起作用。
请对此提供帮助。
谢谢!
经过长时间的搜索,我发现了一些很棒的东西。只需在functions.php中调用您的环境,商人密钥,公共密钥和私有密钥]
Braintree_Configuration::environment($transaction); //Sandbox OR Products
Braintree_Configuration::merchantId($merchant_key); //Your Braintree Merchant Key
Braintree_Configuration::publicKey($public_key); //Your Braintree Public Key
Braintree_Configuration::privateKey($private_key); //Your Braintree Private Key
add_action("gform_after_submission", "after_submission", 10, 2);
function after_submission($entry, $form)
{
//Create Customer
$result = Braintree_Customer::create(array(
'firstName' => 'First Name',
'lastName' => 'Last Name',
'company' => 'Company Name',
'email' => '[email protected]',
));
//Get Current Customer ID
$customer_id = $result->customer->id;
//Add Customer Credit Card Info to Braintree Subscription
$result = Braintree_CreditCard::create(array(
'customerId' => $customer_id,
'number' => '4111111111111111',
'expirationDate' => '05/20',
'cardholderName' => 'Mani'
));
try {
$customer = Braintree_Customer::find($customer_id);
$payment_method_token = $customer->creditCards[0]->token;
//You can add Subscription Package From Braintree Account
$result = Braintree_Subscription::create(array(
'paymentMethodToken' => $payment_method_token,
'planId' => 'Your_subscription_name_here',
'price' => '1000'
));
if ($result->success) {
echo("Success! Subscription " . $result->subscription->id . " is " . $result->subscription->status);
} else {
echo("Validation errors:");
foreach (($result->errors->deepAll()) as $error) {
echo("- " . $error->message);
}
}
} catch (Braintree_Exception_NotFound $e) {
echo("Failure: no customer found with ID " . $customer_id);
}
穆罕默德,我想做同样的事情。我是否将这些代码完全插入我的functions.php文件中?