Has anyone used Gravity Forms to create a form that enables a user to update the credit card information (card number and/or expiration date) used for recurring payments on his subscription at Authorize.net?
Has anyone used Gravity Forms to create a form that enables a user to update the credit card information (card number and/or expiration date) used for recurring payments on his subscription at Authorize.net?
Is this feature being worked on?
Not that I know of. This isn't something within the scope of our current add-on options. I'll move this to Feature Requests for our developers to see.
I ended up doing this myself, using the GF hook "gform_pre_submission", and my own api call using the AuthNet ARB php library. This worked in a proof-of-concept test, and in my AuthNet Sandbox account,.. but I have not actually built it into a real site yet, so use at your own risk.
You should probably clean/sanitize the user input from the $_POST fields, of course change the $_POST field names to match your form.
THE FORM
The form is on a page that is restricted to logged-in users. The ARB api requires the FirstName and LastName to be separate fields (as i recall), but GF's credit card field-group has the Cardholder Name a single input field, so I can't use that Cardholder Name field. Instead i hid that field with jquery, and added a separate Name field-group, with FirstName and LastName as separate fields.
FUNCTIONS.PHP
add_action("gform_pre_submission", "tz_anet_arb_update_cc", 10, 2);
function tz_anet_arb_update_cc($entry,$form) {
# ARB API CONFIG
require (TEMPLATEPATH.'/anet-test/anet_php_sdk/AuthorizeNet.php'); // path to Anet ARB php library
define("AUTHORIZENET_API_LOGIN_ID", $my_anet_api_login_id); // var set elsewhere
define("AUTHORIZENET_TRANSACTION_KEY", $my_anet_api_transaction_id); // var set elsewhere
define("AUTHORIZENET_SANDBOX", true); // true for testing, false for production
define("TEST_REQUEST", "FALSE"); // You may want to set to true if testing against production
# PREP DATA ….
# Card Number
$creditCardCardNumber = $_POST['input_1_1']; // *todo: sanitize
# CCV
$creditCardCardCode = strval(absint(intval($_POST['input_1_3'])));
# Exp date
$exp_month = strval(absint(intval($_POST['input_1_2'][0])));
$exp_month = str_pad($exp_month, 2, '0', STR_PAD_LEFT);
$exp_year = strval(absint(intval($_POST['input_1_2'][1])));
$creditCardExpirationDate = $exp_month ."-".$exp_year;
# Name on Card
$billToFirstName = $_POST['input_2_3']; // *todo: sanitize
$billToLastName = $_POST['input_2_6']; // *todo: sanitize
# PREP REQUEST
$subscription = new AuthorizeNet_Subscription;
$subscription->creditCardCardNumber = $creditCardCardNumber; // test: 4007000000027, 6011000000000012
$subscription->creditCardExpirationDate = $creditCardExpirationDate; // test: 2018-10
$subscription->creditCardCardCode = $creditCardCardCode; // test: 123
$subscription->billToFirstName = $billToFirstName; // test: Bob
$subscription->billToLastName = $billToLastName; // test: Jones
# Get Subscription ID to update
global $current_user;
get_currentuserinfo();
$subscription_id = get_user_meta($current_user->ID, 'current-subscription-id', true); // get from User meta (or Entry)
$request = new AuthorizeNetARB;
$response = $request->updateSubscription($subscription_id, $subscription);
# RESPONSE
// parse and show success or failure accordingly // *todo!
# DEBUG
//echo "<pre>";print_r($response);echo "</pre>";
//echo "<pre>";print_r($_POST);echo "</pre>";
}
Thank you for posting that code.
Tex77, did you ever finish this code out for production? I would love to have a copy of your final version.
@MIke -- Sorry, I never did move that to production. The requirement for enabling a user to update his credit-card info (stored in Authorize.net) was removed from the project.