From 2d63713453b40b767e8b0d398d5644adda6d4ee3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 4 Feb 2015 14:15:46 -0500 Subject: [PATCH] Implement updateSubscriptionBillingInfo method. --- trustcommerce.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/trustcommerce.php b/trustcommerce.php index b1d54a8..4d8bca9 100644 --- a/trustcommerce.php +++ b/trustcommerce.php @@ -20,6 +20,7 @@ * * Written and contributed by Ward Vandewege (http://www.fsf.org) * Modified by Lisa Marie Maginnis (http://www.fsf.org) + * Copyright © 2015 David Thompson * */ @@ -156,6 +157,60 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment { } } + /** + * Update CC info for a recurring contribution + */ + function updateSubscriptionBillingInfo(&$message = '', $params = array()) { + $expYear = $params['credit_card_exp_date']['Y']; + $expMonth = $params['credit_card_exp_date']['M']; + + $tc_params = array( + 'custid' => $this->_paymentProcessor['user_name'], + 'password' => $this->_paymentProcessor['password'], + 'action' => 'store', + 'billingid' => $params['subscriptionId'], + 'avs' => 'y', // Enable address verification + 'address1' => $params['street_address'], + 'zip' => $params['postal_code'], + 'name' => $this->_formatBillingName($params['first_name'], + $params['last_name']), + 'cc' => $params['credit_card_number'], + 'cvv' => $params['cvv2'], + 'exp' => $this->_formatExpirationDate($expYear, $expMonth), + 'amount' => $this->_formatAmount($params['amount']), + ); + + CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $tc_params); + + $reply = $this->_sendTCRequest($tc_params); + $result = $this->_getTCReply($reply); + + if($result === 0) { + $message = 'Successfully updated TC billing id ' . $tc_params['billingid']; + + return TRUE; + } else { + return FALSE; + } + } + + // TODO: Use the formatting functions throughout the entire class to + // dedupe the conversions done elsewhere in a less reusable way. + function _formatAmount($amount) { + return $amount * 100; + } + + function _formatBillingName($firstName, $lastName) { + return "$firstName $lastName"; + } + + function _formatExpirationDate($year, $month) { + $exp_month = str_pad($month, 2, '0', STR_PAD_LEFT); + $exp_year = substr($year, -2); + + return "$exp_month$exp_year"; + } + function _isBlacklisted() { if($this->_isIPBlacklisted()) { return TRUE; -- 2.25.1