經過很長時間的搜索,我發現了一些很棒的東西。 就打電話給你的環境,商家,公鑰和私鑰的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);
}
如果您正在使用重力形式與開發插件,我建議您提交票給他們,他們的支持非常出色。然後回來並添加你自己的答案:) – McNab 2015-03-02 10:02:33