PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Allow user to update the credit card info used for ARB?

  1. tex77
    Member

    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?

    Posted 6 years ago on Saturday August 18, 2012 | Permalink
  2. Is this feature being worked on?

    Posted 6 years ago on Friday September 14, 2012 | Permalink
  3. David Peralty
    Administrator

    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.

    Posted 6 years ago on Friday September 14, 2012 | Permalink
  4. tex77
    Member

    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>";
    }
    Posted 6 years ago on Friday September 14, 2012 | Permalink
  5. Thank you for posting that code.

    Posted 6 years ago on Friday September 14, 2012 | Permalink
  6. Tex77, did you ever finish this code out for production? I would love to have a copy of your final version.

    Posted 6 years ago on Wednesday January 16, 2013 | Permalink
  7. tex77
    Member

    @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.

    Posted 6 years ago on Tuesday February 12, 2013 | Permalink