Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rudimentary support for basic Chase PaymentTech methods completed

  • Loading branch information...
commit 4c8bd4dfb06cab6322b57cb238313fa55dafdc3c 1 parent 7e934da
Calvin Froedge authored September 27, 2011
137  config/payments/chase_paymenttech.php
... ...
@@ -0,0 +1,137 @@
  1
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2
+
  3
+/*
  4
+|--------------------------------------------------------------------------
  5
+| Notes & Unsupported Parameters
  6
+|--------------------------------------------------------------------------
  7
+|
  8
+|The following parameters were omitted:
  9
+| - IndustryType
  10
+| - CurrencyExponent
  11
+| - AVSzip
  12
+| - AVSaddress1
  13
+| - AVSaddress2
  14
+| - AVScity
  15
+| - AVSstate
  16
+| - AVSphoneNum
  17
+| - AVSname
  18
+| - CustomerRefNum - Customer supplied identifier for the transaction
  19
+| - OrderID - Customer supplied OrderID
  20
+*/
  21
+
  22
+
  23
+/*
  24
+|--------------------------------------------------------------------------
  25
+| Payment Gateway Credentials
  26
+|--------------------------------------------------------------------------
  27
+|
  28
+| Fill out the following information with those provided 
  29
+| to you by your gateway.
  30
+| 
  31
+*/
  32
+$config['api_username']		= "HELLONEWORK27"; // The Username for the API
  33
+$config['api_password'] = "SJMHBVF67L9CW"; // The Password for the API
  34
+$config['api_merchant_id'] = '700000202915';
  35
+$config['api_terminal_id'] = '001';
  36
+
  37
+$config['api_customer_ref_number_settings'] = 'A'; /* Possible Values:
  38
+A: Auto-generate the Customer Reference Number. In other words, the Orbital Gateway will assign the Customer Reference Number and return it in the response.
  39
+S: The Orbital Gateway will use the value passed in the <CustomerRefNum> element as the Customer Reference Number.
  40
+O: This option only relates to when a Profile is added as a part of an authorization request. In this circumstance, the value passed in the <OrderID> element is used as the Customer Reference Number. For example, this would be used in circumstances wherein the Order ID also represents your customerÕs identification in your system, such as a Policy Number for an insurance company.
  41
+D: This option only relates to when a Profile is added as a part of an authorization request. In this circumstance, the value passed in the <Comments> element is used as the Customer Reference*/
  42
+
  43
+$config['api_customer_profile_order_override'] = 'NO';/*
  44
+The Orbital Gateway has configuration options for the Profile setup to determine how the Customer Reference Number is leveraged to populate other data sets using the <CustomerProfileOrderOverrideInd> value.
  45
+The options are:
  46
+NO
  47
+No mapping to order data.
  48
+OI
  49
+Pre-populate <OrderID> with the Customer Reference Number.
  50
+OD
  51
+Pre-populate the <Comments> field (this field is called Order Description in the Virtual Terminal) with the Customer Reference Number.
  52
+The relevance of this feature is on the PNS platform (BIN 000002), where the <Comments> field populates the Customer-Definable Data. This data can then be made available on certain Resource Online Reports. Any questions about your reports should be directed to your Relationship Manager.
  53
+OA
  54
+Pre-populate the <OrderId> and <Comments> fields with the Customer Reference Number.*/
  55
+
  56
+
  57
+/*
  58
+|--------------------------------------------------------------------------
  59
+| Payment Gateway Settings
  60
+|--------------------------------------------------------------------------
  61
+|
  62
+| You should be able to leave these alone unless the API changes.
  63
+| 
  64
+*/
  65
+$config['api_endpoint_test'] = "https://orbitalvar1.paymentech.net/authorize";
  66
+$config['api_endpoint_production'] = "https://orbital1.paymentech.net/authorize";
  67
+$config['api_version'] = "PTI51";
  68
+$config['paymentech_BIN'] = '000002';//BIN 000001 (Salem Platform) or BIN 000002 (PNS Platform).  See section 3.3.1.1 in orbital_gateway_xml_specification.pdf
  69
+$config['test_mode'] = TRUE;
  70
+
  71
+
  72
+/*
  73
+|--------------------------------------------------------------------------
  74
+| Payment to Gateway Key Map
  75
+|--------------------------------------------------------------------------
  76
+|
  77
+| This allows you to setup a centralized key map conversion table.
  78
+| The array key is CodeIgniter Payments key and the value is the 
  79
+| current gateways (e.g. Chase PaymentsTech) key
  80
+| 
  81
+| NOTE: If the key doesn't exist for your gateway, remove the
  82
+| key or set it to FALSE to prevent it from being passed
  83
+| 
  84
+| This array will be used in the private function _map_params()
  85
+|
  86
+*/
  87
+$config['payment_to_gateway_key_map'] = array(
  88
+			'cc_type'			=> 'CardBrand',	//SW Switch/Solo, ED European Direct Debit, DP PINless Debit (Generic Value Used in Requests), IM International Maestro
  89
+			'cc_number'			=> 'AccountNum', //Credit card number
  90
+			'cc_exp'			=> 'Exp', //Must be formatted MMYYYY @todo - Must translate to MMYY
  91
+			'cc_code'			=> 'CardSecVal', //3 or 4 digit cvv code
  92
+			'street'			=> 'AVSaddress1', //street address of the purchaser @todo - Only 64 Char
  93
+			'street2'			=> 'AVSaddress2', //street address 2 of purchaser @todo - Only 64 Char
  94
+			'city'				=> 'AVScity', //city of the purchaser @todo - Only 32 Char
  95
+			'state'				=> 'AVSstate', //state of the purchaser @todo - Only 16 Char; 2 lttr abbr pref.
  96
+			'country'			=> 'AVScountryCode', // country of the purchaser (64 Char)
  97
+			'postal_code'		=> 'AVSzip', //zip code of the purchaser (16 Char)
  98
+			'amt'				=> 'Amount', //purchase amount (XXXXXXX.XX FORMAT) Includes Tax and Tip
  99
+			'phone'				=> 'AVSphoneNum', //phone num of customer shipped to @todo - Required for ACH; 16 Chars.
  100
+			'identifier' 		=> 'TxRefNum', //Merchant provided identifier for the transaction @todo - IS PREVIOUS TRANS_ID AND ONLY REQUIRED FOR CAPTURE OR REFUND.
  101
+			'currency_code'		=> 'CurrencyCode', //currency code to use for the transaction.
  102
+);
  103
+
  104
+/*
  105
+|--------------------------------------------------------------------------
  106
+| Required Parameters
  107
+|--------------------------------------------------------------------------
  108
+|
  109
+| Avoid sending payments to the gateway unless param requirements are met
  110
+| 
  111
+| NOTE: You should setup form_validation to prevent these parameters
  112
+|  from being missed on the payment page.
  113
+|
  114
+*/
  115
+$config['required_params'] = array(
  116
+	'oneoff_payment'	=> array(
  117
+		'cc_number',
  118
+		'cc_code',
  119
+		'cc_exp',
  120
+		'amt'
  121
+	),
  122
+	'authorize_payment'	=> array(
  123
+		'cc_number',
  124
+		'cc_code',
  125
+		'cc_exp',
  126
+		'amt'	
  127
+	),
  128
+	'capture_payment'	=> array(
  129
+		'identifier'
  130
+	),
  131
+	'void_payment'		=> array(
  132
+		'identifier'
  133
+	),
  134
+	'refund_payment'	=> array(
  135
+		'identifier'
  136
+	)
  137
+);
362  libraries/payments/chase_paymenttech.php
... ...
@@ -0,0 +1,362 @@
  1
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2
+
  3
+class Chase_PaymentTech
  4
+{	
  5
+	/**
  6
+	 * Default params for a given method
  7
+	*/	
  8
+	private $_default_params;
  9
+	
  10
+	/**
  11
+	 * The endpoint the request is to use
  12
+	*/
  13
+	private $_api_endpoint;
  14
+
  15
+	/**
  16
+	 * An array containing settings
  17
+	*/
  18
+	private $_api_settings;	
  19
+	
  20
+	/**
  21
+	 * An array containing a key map of all transaction params
  22
+	*/
  23
+	private $_key_map;
  24
+		
  25
+	/**
  26
+	 * Constructor method
  27
+	*/		
  28
+	public function __construct($payments)
  29
+	{
  30
+		$this->payments = $payments;				
  31
+		$this->_default_params = $this->payments->ci->config->item('method_params');
  32
+		$this->_api_endpoint = $this->payments->ci->config->item('api_endpoint'.'_'.$this->payments->mode);
  33
+		$this->_key_map = $this->payments->ci->config->item('payment_to_gateway_key_map');
  34
+
  35
+		$this->_api_settings = array(
  36
+			'xml_version'	=> '1.0',
  37
+			'encoding'		=> 'utf-8',
  38
+		);
  39
+	}
  40
+
  41
+	/**
  42
+	 * Builds a request
  43
+	 * @param	array	array of params
  44
+	 * @param	string	the api call to use
  45
+	 * @param	string	the type of transaction
  46
+	 * @return	array	Array of transaction settings
  47
+	*/	
  48
+	private function _build_request($params, $transaction_type = NULL)
  49
+	{
  50
+		//Start the request with common fields
  51
+		$nodes[$this->_api_method] = $this->_common_request_fields($transaction_type);
  52
+
  53
+		$nodes[$this->_api_method]['MessageType'] = $transaction_type;
  54
+		
  55
+		foreach($params as $k=>$v)
  56
+		{
  57
+			//print $k.':'.$v;
  58
+			if($k == 'cc_exp')
  59
+			{
  60
+				$mm = substr($v, 0, 2);
  61
+				$yy = substr($v, -2);
  62
+				$nodes[$this->_api_method][$this->_key_map[$k]] = $mm.$yy;
  63
+				unset($k);
  64
+				continue;
  65
+			}
  66
+			
  67
+			if($k == 'amt')
  68
+			{
  69
+				if(strpos($v, '.'))
  70
+				{
  71
+					$v = str_replace('.', '', $v);
  72
+				}
  73
+				else
  74
+				{
  75
+					$v .= '00';
  76
+				}
  77
+				$nodes[$this->_api_method][$this->_key_map[$k]] = $v;
  78
+				unset($k);
  79
+				continue;
  80
+			}
  81
+						
  82
+			if(!is_null($v) && strlen($v) > 0)
  83
+			{
  84
+				$nodes[$this->_api_method][$this->_key_map[$k]] = $v;
  85
+			}
  86
+		}
  87
+										
  88
+		$request = $this->payments->build_xml_request(
  89
+			$this->_api_settings['xml_version'],
  90
+			$this->_api_settings['encoding'],
  91
+			$nodes,					
  92
+			'Request'
  93
+		);
  94
+		
  95
+		/*If recurring transaction types, use Status param - A Active, I Inactive, MS Manual Suspend
  96
+		
  97
+			nodes MBType = R
  98
+			
  99
+			nodes MBOrderIdGenerationMethod = DI
  100
+				Valid values:
  101
+				IO Use the Customer Reference Number (Profile ID). This value is made up of the capital letters I and O, not numbers.
  102
+				DI Dynamically generate the Order ID. This value is made up of the capital letters D and I, no numbers.			
  103
+			
  104
+			nodes MBRecurringStartDate = MMDDYYYY
  105
+
  106
+				To allow the Managed Billing engine to properly calculate and schedule all billings, this date must be at least one day after the request date (a recurring billing cycle can never begin on the date that the request message is sent to the Orbital system).
  107
+				
  108
+			nodes MBRecurringEndDate = MMDDYYYY
  109
+			
  110
+			if no start date / end date supplied, MBRecurringNoEndDateFlag	= Y, else = N
  111
+			
  112
+			nodes MBRecurringMaxBillings = 1-999999
  113
+			
  114
+			nodes MBRecurringFrequency = 
  115
+				Field
  116
+				Allowed Values
  117
+				Allowed Special Chars
  118
+				Day-of-month
  119
+				1Ð31
  120
+				, - * ? / L W
  121
+				Month
  122
+				1Ð12 or JANÐDEC
  123
+				, - * /
  124
+				Day-of-week
  125
+				1Ð7 or SUNÐSAT
  126
+				, - * ? / L #					
  127
+			
  128
+			nodes MBDeferredBillDate			
  129
+		*/
  130
+		
  131
+		/* If refund or credit
  132
+			nodes TxRefNum	=	identifier
  133
+		*/
  134
+		
  135
+		var_dump($request);exit;
  136
+		
  137
+		return $request;	
  138
+	}
  139
+	
  140
+	private function _common_request_fields($transaction_type)
  141
+	{
  142
+		return array(
  143
+			'OrbitalConnectionUsername' 		=> $this->payments->ci->config->item('api_username'),
  144
+			'OrbitalConnectionPassword'		 	=> $this->payments->ci->config->item('api_password'),
  145
+			'MessageType'						=> $transaction_type,
  146
+			'BIN'								=> $this->payments->ci->config->item('paymentech_BIN'),
  147
+			'MerchantID'						=> $this->payments->ci->config->item('api_merchant_id'),
  148
+			'TerminalID'						=> $this->payments->ci->config->item('api_terminal_id'),
  149
+			'CustomerProfileFromOrderInd' 		=> $this->payments->ci->config->item('api_customer_ref_number_settings'),
  150
+			'CustomerProfileOrderOverrideInd'	=> $this->payments->ci->config->item('api_customer_profile_order_override')
  151
+		);
  152
+	}
  153
+		
  154
+	/**
  155
+	 * Make a oneoff payment
  156
+	 * @param	array	An array of payment params, sent from your controller / library
  157
+	 * @return	object	The response from the payment gateway
  158
+	*/	
  159
+	public function chase_paymenttech_oneoff_payment($params)
  160
+	{
  161
+		$this->_api_method = 'NewOrder';
  162
+		$this->_request = $this->_build_request($params, 'AC');			
  163
+		return $this->_handle_query();
  164
+	}
  165
+
  166
+	/**
  167
+	 * Authorize a oneoff payment
  168
+	 * @param	array	An array of payment params, sent from your controller / library
  169
+	 * @return	object	The response from the payment gateway
  170
+	*/	
  171
+	public function chase_paymenttech_authorize_payment($params)
  172
+	{
  173
+		$this->_api_method = 'NewOrder';
  174
+		$this->_request = $this->_build_request($params, 'A');			
  175
+		return $this->_handle_query();
  176
+	}
  177
+
  178
+	/**
  179
+	 * Capture a oneoff payment
  180
+	 * @param	array	An array of payment params, sent from your controller / library
  181
+	 * @return	object	The response from the payment gateway
  182
+	*/	
  183
+	public function chase_paymenttech_capture_payment($params)
  184
+	{
  185
+		$this->_api_method = 'FC';
  186
+		$this->_request = $this->_build_request($params, 'FC');			
  187
+		return $this->_handle_query();
  188
+	}
  189
+
  190
+	/**
  191
+	 * Get the details for a particular transaction
  192
+	 * @param	array	An array of payment params, sent from your controller / library
  193
+	 * @return	object	The response from the payment gateway
  194
+	*/	
  195
+	public function chase_paymenttech_get_transaction_details($params)
  196
+	{
  197
+		$this->_api_method = 'getTransactionDetailsRequest';
  198
+		$this->_request = $this->_build_request($params);			
  199
+		return $this->_handle_query();
  200
+	}	
  201
+	
  202
+	/**
  203
+	 * Refund a transaction
  204
+	 * @param	array	An array that contains your identifier
  205
+	 * @return	object	The response from the payment gateway
  206
+	 *
  207
+	 * NOTE:  This submits a LINKED credit.  Authorize.net supports both linked credits and unlinked credits.  Linked credit refunds must be submitted wthin 120 days of original settlement, and must be associated with a particular transaction.  Unlinked credits allow you to submit refunds for payments not submitted through the gateway, or beyond the 120 day period.  If you want to do unlinked credits, check this out: http://www.authorize.net/files/ecc.pdf
  208
+	*/	
  209
+	public function chase_paymenttech_refund_payment($params)
  210
+	{
  211
+		$this->_api_method = 'NewOrder';
  212
+		$this->_request = $this->_build_request($params, 'R');		
  213
+		return $this->_handle_query();	
  214
+	}	
  215
+		
  216
+	/**
  217
+	 * Create a new recurring payment
  218
+	 *
  219
+	 * @param	array
  220
+	 * @return	object
  221
+	 *
  222
+	 */		
  223
+	public function chase_paymenttech_recurring_payment($params)
  224
+	{
  225
+		$this->_api_method = 'ARBCreateSubscriptionRequest';
  226
+		$this->_request = $this->_build_request($params);	
  227
+		return $this->_handle_query();
  228
+	}	
  229
+
  230
+	/**
  231
+	 * Get profile info for a particular profile id
  232
+	 *
  233
+	 * @param	array
  234
+	 * @return	object
  235
+	 */		
  236
+	public function chase_paymenttech_get_recurring_profile($params)
  237
+	{	
  238
+		$this->_api_method = 'ARBGetSubscriptionStatusRequest';
  239
+		$this->_request = $this->_build_request($params);	
  240
+		return $this->_handle_query();
  241
+	}
  242
+
  243
+	/**
  244
+	 * Update a recurring payments profile
  245
+	 *
  246
+	 * @param	array
  247
+	 * @return	object
  248
+	 * NOTE:
  249
+		* The subscription start date (subscription.paymentSchedule.startDate) may only be updated in the event that no successful payments have been completed.
  250
+		´ The subscription interval information (subscription.paymentSchedule.interval.length and subscription.paymentSchedule.interval.unit) may not be updated.
  251
+		´ The number of trial occurrences (subscription.paymentSchedule.trialOccurrences) may only be updated if the subscription has not yet begun or is still in the trial period.
  252
+		´ All other fields are optional.	 
  253
+	 */		
  254
+	public function chase_paymenttech_update_recurring_profile($params)
  255
+	{		
  256
+		$this->_api_method = 'ARBUpdateSubscriptionRequest';
  257
+		$this->_request = $this->_build_request($params);		
  258
+		return $this->_handle_query();
  259
+	}
  260
+	
  261
+	/**
  262
+	 * Cancel a recurring profile
  263
+	 *
  264
+	 * @param	array
  265
+	 * @return	object
  266
+	 */		
  267
+	public function chase_paymenttech_cancel_recurring_profile($params)
  268
+	{	
  269
+		$this->_api_method = 'ARBCancelSubscriptionRequest';
  270
+		$this->_request = $this->_build_request($params);
  271
+		return $this->_handle_query();
  272
+	}			
  273
+
  274
+	/**
  275
+	 * Build the query for the response and call the request function
  276
+	 *
  277
+	 * @param	array
  278
+	 * @param	array
  279
+	 * @param	string
  280
+	 * @return	array
  281
+	 */		
  282
+	private function _handle_query()
  283
+	{	
  284
+		$this->_http_query = $this->_request;
  285
+		
  286
+		$response_object = $this->payments->gateway_request($this->_api_endpoint, $this->_http_query);
  287
+		$response = $this->_parse_response($response_object);
  288
+		
  289
+		return $response;
  290
+	}
  291
+
  292
+	/**
  293
+	 * Parse the response from the server
  294
+	 *
  295
+	 * @param	array
  296
+	 * @return	object
  297
+	 */		
  298
+	private function _parse_response($xml)
  299
+	{	
  300
+		$details = (object) array();
  301
+
  302
+		$as_array = $this->payments->arrayize_object($xml);
  303
+
  304
+		$result = $as_array['messages']['resultCode'];
  305
+		
  306
+		if(isset($as_array['transactionResponse']))
  307
+		{
  308
+			$identifier = $as_array['transactionResponse']['transId'];
  309
+		}
  310
+		
  311
+		if(isset($as_array['subscriptionId']))
  312
+		{
  313
+			$identifier = $as_array['subscriptionId'];
  314
+		}
  315
+		
  316
+		$timestamp = gmdate('c');
  317
+		$details->timestamp = $timestamp;
  318
+		$details->gateway_response = $as_array;
  319
+		
  320
+		if(isset($identifier) AND strlen($identifier) > 1)
  321
+		{
  322
+			$details->identifier = $identifier;
  323
+		}
  324
+		
  325
+		if($result == 'Ok')
  326
+		{
  327
+			return $this->payments->return_response(
  328
+				'Success',
  329
+				$this->payments->payment_type.'_success',
  330
+				'gateway_response',
  331
+				$details
  332
+			);
  333
+		}
  334
+		
  335
+		if($result == 'Error')
  336
+		{
  337
+			if(isset($as_array['transactionResponse']['errors']['error']['errorText']))
  338
+			{
  339
+				$message = $as_array['transactionResponse']['errors']['error']['errorText'];
  340
+			}
  341
+			
  342
+			if(isset($as_array['messages']['message']['text']))
  343
+			{
  344
+				$message = $as_array['messages']['message']['text'];
  345
+			}
  346
+			
  347
+			if(isset($message))
  348
+			{
  349
+				$details->reason = $message;
  350
+			}	
  351
+
  352
+			return $this->payments->return_response(
  353
+				'Failure',
  354
+				$this->payments->payment_type.'_gateway_failure',
  355
+				'gateway_response',
  356
+				$details
  357
+			);				
  358
+		}
  359
+	}
  360
+			
  361
+		
  362
+}

0 notes on commit 4c8bd4d

Please sign in to comment.
Something went wrong with that request. Please try again.