/app/gateway/authorize/class-ms-gateway-authorize.php

  1. <?php 
  2. /** 
  3. * Authorize.net Gateway. 
  4. * 
  5. * Must use SSL to send card info to gateway. 
  6. * Integrate Authorize.net gateway send payment requests. 
  7. * 
  8. * Persisted by parent class MS_Model_Option. Singleton. 
  9. * 
  10. * @since 1.0.0 
  11. * @package Membership2 
  12. * @subpackage Model 
  13. */ 
  14. class MS_Gateway_Authorize extends MS_Gateway { 
  15.  
  16. const ID = 'authorize'; 
  17.  
  18. /** 
  19. * Gateway singleton instance. 
  20. * 
  21. * @since 1.0.0 
  22. * @var string $instance 
  23. */ 
  24. public static $instance; 
  25.  
  26. /** 
  27. * Authorize.net's Customer Information Manager wrapper. 
  28. * 
  29. * @since 1.0.0 
  30. * @var string $cim 
  31. */ 
  32. protected static $cim = ''; 
  33.  
  34. /** 
  35. * Authorize.net API login IP. 
  36. * 
  37. * @see @link https://www.authorize.net/support/CP/helpfiles/Account/Settings/Security_Settings/General_Settings/API_Login_ID_and_Transaction_Key.htm 
  38. * @since 1.0.0 
  39. * @var string $api_login_id 
  40. */ 
  41. protected $api_login_id = ''; 
  42.  
  43. /** 
  44. * Authorize.net API transaction key. 
  45. * 
  46. * @since 1.0.0 
  47. * @var string $api_transaction_key 
  48. */ 
  49. protected $api_transaction_key = ''; 
  50.  
  51. /** 
  52. * Secure transactions flag. 
  53. * If set to true then each payment request will include the users credit 
  54. * card verificaton code (CVC). This means that all recurring payments need 
  55. * the user to enter the CVC code again. 
  56. * 
  57. * @since 1.0.0 
  58. * @var bool $secure_cc 
  59. */ 
  60. protected $secure_cc = false; 
  61.  
  62.  
  63. /** 
  64. * Initialize the object. 
  65. * 
  66. * @since 1.0.0 
  67. */ 
  68. public function after_load() { 
  69. parent::after_load(); 
  70.  
  71. $this->id = self::ID; 
  72. $this->name = __( 'Authorize.net Gateway', 'membership2' ); 
  73. $this->group = 'Authorize.net'; 
  74. $this->manual_payment = true; // Recurring billed/paid manually 
  75. $this->pro_rate = true; 
  76.  
  77. /** 
  78. * Processes purchase action. 
  79. * 
  80. * This function is called when a payment was made: We check if the 
  81. * transaction was successful. If it was we call `$invoice->changed()` which 
  82. * will update the membership status accordingly. 
  83. * 
  84. * @since 1.0.0 
  85. * @param MS_Model_Relationship $subscription The related membership relationship. 
  86. */ 
  87. public function process_purchase( $subscription ) { 
  88. do_action( 
  89. 'ms_gateway_authorize_process_purchase_before',  
  90. $subscription,  
  91. $this 
  92. ); 
  93.  
  94. if ( ! is_ssl() ) { 
  95. throw new Exception( __( 'You must use HTTPS in order to do this', 'membership' ) ); 
  96.  
  97. $invoice = $subscription->get_current_invoice(); 
  98. $member = $subscription->get_member(); 
  99.  
  100. // manage authorize customer profile 
  101. $cim_profile_id = $this->get_cim_profile_id( $member ); 
  102.  
  103. if ( empty( $cim_profile_id ) ) { 
  104. $this->create_cim_profile( $member ); 
  105. } elseif ( $cim_payment_profile_id = trim( filter_input( INPUT_POST, 'profile' ) ) ) { 
  106. // Fetch for user selected cim profile 
  107. $response = $this->get_cim()->getCustomerPaymentProfile( $cim_profile_id, $cim_payment_profile_id ); 
  108.  
  109. if ( $response->isError() ) { 
  110. throw new Exception( 
  111. __( 'The selected payment profile is invalid, enter a new credit card', 'membership2' ) 
  112. ); 
  113. } else { 
  114. $this->update_cim_profile( $member ); 
  115.  
  116. if ( ! $invoice->is_paid() ) { 
  117. // Not paid yet, request the transaction. 
  118. $this->online_purchase( $invoice, $member, 'process' ); 
  119. } elseif ( 0 == $invoice->total ) { 
  120. // Paid and free. 
  121. $invoice->changed(); 
  122.  
  123. return apply_filters( 
  124. 'ms_gateway_authorize_process_purchase',  
  125. $invoice,  
  126. $this 
  127. ); 
  128.  
  129. /** 
  130. * Request automatic payment to the gateway. 
  131. * 
  132. * @since 1.0.0 
  133. * @param MS_Model_Relationship $subscription The related membership relationship. 
  134. * @return bool True on success. 
  135. */ 
  136. public function request_payment( $subscription ) { 
  137. $was_paid = false; 
  138.  
  139. do_action( 
  140. 'ms_gateway_authorize_request_payment_before',  
  141. $subscription,  
  142. $this 
  143. ); 
  144.  
  145. $member = $subscription->get_member(); 
  146. $invoice = $subscription->get_current_invoice(); 
  147.  
  148. if ( ! $invoice->is_paid() ) { 
  149. // Not paid yet, request the transaction. 
  150. $was_paid = $this->online_purchase( $invoice, $member, 'request' ); 
  151. } else { 
  152. // Invoice was already paid earlier. 
  153. $was_paid = true; 
  154.  
  155. do_action( 
  156. 'ms_gateway_authorize_request_payment_after',  
  157. $subscription,  
  158. $was_paid,  
  159. $this 
  160. ); 
  161.  
  162. return $was_paid; 
  163.  
  164. /** 
  165. * Processes online payments. 
  166. * 
  167. * Send to Authorize.net to process the payment immediatly. 
  168. * 
  169. * @since 1.0.0 
  170. * @param MS_Model_Invoice $invoice The invoice to pay. 
  171. * @param MS_Model_Member The member paying the invoice. 
  172. * @return bool True on success, otherwise throws an exception. 
  173. */ 
  174. protected function online_purchase( &$invoice, $member, $log_action ) { 
  175. $success = false; 
  176. $notes = ''; 
  177. $amount = 0; 
  178. $subscription = $invoice->get_subscription(); 
  179.  
  180. do_action( 
  181. 'ms_gateway_authorize_online_purchase_before',  
  182. $invoice,  
  183. $member,  
  184. $this 
  185. ); 
  186.  
  187. $need_code = lib3()->is_true( $this->secure_cc ); 
  188. $have_code = ! empty( $_POST['card_code'] ); 
  189.  
  190. if ( 0 == $invoice->total ) { 
  191. $notes = __( 'Total is zero. Payment approved. Not sent to gateway.', 'membership2' ); 
  192. $invoice->pay_it( MS_Gateway_Free::ID, '' ); 
  193. $invoice->add_notes( $notes ); 
  194. $invoice->save(); 
  195. $invoice->changed(); 
  196. } elseif ( ! $need_code || $have_code ) { 
  197. $amount = MS_Helper_Billing::format_price( $invoice->total ); 
  198.  
  199. $cim_transaction = $this->get_cim_transaction( $member ); 
  200. $cim_transaction->amount = $amount; 
  201. $cim_transaction->order->invoiceNumber = $invoice->id; 
  202.  
  203. $invoice->timestamp = time(); 
  204. $invoice->save(); 
  205.  
  206. $_POST['API Out: Secure Payment'] = lib3()->is_true( $this->secure_cc ); 
  207. $_POST['API Out: CustomerProfileID'] = $cim_transaction->customerProfileId; 
  208. $_POST['API Out: PaymentProfileID'] = $cim_transaction->customerPaymentProfileId; 
  209. $_POST['API Out: InvoiceNumber'] = $cim_transaction->order->invoiceNumber; 
  210.  
  211. $response = $this->get_cim()->createCustomerProfileTransaction( 
  212. 'AuthCapture',  
  213. $cim_transaction 
  214. ); 
  215.  
  216. if ( ! empty( $response->xml ) 
  217. && ! empty( $response->xml->messages ) 
  218. && ! empty( $response->xml->messages->message ) 
  219. ) { 
  220. $msg = $response->xml->messages->message; 
  221. $_POST['API Response: Short'] = $msg->code . ': ' . $msg->text; 
  222. } else { 
  223. $_POST['API Response: Short'] = '-'; 
  224. if ( isset( $response->response ) ) { 
  225. if ( is_string( $response->response ) ) { 
  226. $_POST['API Response: XML'] = $response->response; 
  227. } else { 
  228. $_POST['API Response: XML'] = json_encode( $response->response ); 
  229. } else { 
  230. $_POST['API Response: XML'] = json_encode( $response->response ); 
  231.  
  232. if ( $response->isOk() ) { 
  233. $transaction_response = $response->getTransactionResponse(); 
  234.  
  235. if ( $transaction_response->approved ) { 
  236. $external_id = $response->getTransactionResponse()->transaction_id; 
  237. $invoice->pay_it( self::ID, $external_id ); 
  238. $success = true; 
  239. $notes = __( 'Payment successful', 'membership2' ); 
  240. } else { 
  241. $notes = sprintf( 
  242. __( 'Payment Failed: code %s, subcode %s, reason code %, reason %s', 'membership2' ),  
  243. $transaction_response->response_code,  
  244. $transaction_response->response_subcode,  
  245. $transaction_response->response_reason_code,  
  246. $transaction_response->response_reason 
  247. ); 
  248. } else { 
  249. $notes = __( 'Payment Failed: ', 'membership2' ) . $response->getMessageText(); 
  250. } elseif ( $need_code && ! $have_code ) { 
  251. $notes = __( 'Secure payment failed: No Card Code found', 'membership2' ); 
  252.  
  253. // Mask the credit card number before logging it to database. 
  254. $card_num = ''; 
  255. $card_code = ''; 
  256. if ( isset( $_POST['card_num'] ) ) { 
  257. // Card Num 6789765435678765 
  258. // Becomes ************8765 
  259. $card_num = str_replace( ' ', '', $_POST['card_num'] ); 
  260. $_POST['card_num'] = str_pad( 
  261. substr( $card_num, -4 ),  
  262. strlen( $card_num ),  
  263. '*',  
  264. STR_PAD_LEFT 
  265. ); 
  266. if ( isset( $_POST['card_code'] ) ) { 
  267. $card_code = $_POST['card_code']; 
  268. $_POST['card_code'] = str_repeat( '*', strlen( $card_code ) ); 
  269.  
  270. do_action( 
  271. 'ms_gateway_transaction_log',  
  272. self::ID, // gateway ID 
  273. $log_action, // request|process|handle 
  274. $success, // success flag 
  275. $subscription->id, // subscription ID 
  276. $invoice->id, // invoice ID 
  277. $amount, // charged amount 
  278. $notes, // Descriptive text 
  279. $external_id // External ID 
  280. ); 
  281.  
  282. // Restore the POST data in case it's used elsewhere. 
  283. $_POST['card_num'] = $card_num; 
  284. $_POST['card_code'] = $card_code; 
  285. unset( $_POST['API Out: CustomerProfileID'] ); 
  286. unset( $_POST['API Out: PaymentProfileID'] ); 
  287. unset( $_POST['API Out: InvoiceNumber'] ); 
  288. unset( $_POST['API Out: Secure Payment'] ); 
  289. unset( $_POST['API Response: Short'] ); 
  290. unset( $_POST['API Response: XML'] ); 
  291.  
  292. return $success; 
  293.  
  294. /** 
  295. * Save card info. 
  296. * 
  297. * Save only 4 last digits and expire date. 
  298. * 
  299. * @since 1.0.0 
  300. * @param MS_Model_Member $member The member to save card info. 
  301. */ 
  302. public function save_card_info( $member ) { 
  303. $cim_profile_id = $this->get_cim_profile_id( $member ); 
  304. $cim_payment_profile_id = $this->get_cim_payment_profile_id( $member ); 
  305. $profile = $this->get_cim_profile( $member ); 
  306.  
  307. if ( ! empty( $profile['customerPaymentProfileId'] ) 
  308. && $cim_payment_profile_id == $profile['customerPaymentProfileId'] 
  309. ) { 
  310. $exp_year = filter_input( INPUT_POST, 'exp_year', FILTER_VALIDATE_INT ); 
  311. $exp_month = substr( filter_input( INPUT_POST, 'exp_month', FILTER_VALIDATE_INT ), -2 ); 
  312. $member->set_gateway_profile( 
  313. self::ID,  
  314. 'card_exp',  
  315. gmdate( 'Y-m-t', strtotime( "{$exp_year}-{$exp_month}-01" ) ) 
  316. ); 
  317.  
  318. $member->set_gateway_profile( 
  319. self::ID,  
  320. 'card_num',  
  321. str_replace( 'XXXX', '', $profile['payment']['creditCard']['cardNumber'] ) 
  322. ); 
  323.  
  324. do_action( 
  325. 'ms_gateway_authorize_save_card_info_after',  
  326. $member,  
  327. $this 
  328. ); 
  329.  
  330. /** 
  331. * Loads Authorize.net lib. 
  332. * 
  333. * @since 1.0.0 
  334. */ 
  335. protected function load_authorize_lib() { 
  336. do_action( 'ms_gateway_authorize_load_authorize_lib', $this ); 
  337.  
  338. require_once MS_Plugin::instance()->dir . '/lib/authorize.net/autoload.php'; 
  339.  
  340. /** 
  341. * Returns the instance of AuthorizeNetCIM class. 
  342. * 
  343. * @since 1.0.0 
  344. * 
  345. * @return M2_AuthorizeNetCIM The instance of AuthorizeNetCIM class. 
  346. */ 
  347. protected function get_cim() { 
  348. $cim = null; 
  349.  
  350. if ( ! empty( self::$cim ) ) { 
  351. $cim = self::$cim; 
  352. } else { 
  353. $this->load_authorize_lib(); 
  354.  
  355. $cim = new M2_AuthorizeNetCIM( $this->api_login_id, $this->api_transaction_key ); 
  356. $cim->setSandbox( ! $this->is_live_mode() ); 
  357.  
  358. if ( WDEV_DEBUG ) { // defined in wpmu-lib submodule. 
  359. $cim->setLogFile( WP_CONTENT_DIR . '/authorize-net.log' ); 
  360. self::$cim = $cim; 
  361.  
  362. return apply_filters( 
  363. 'ms_gateway_authorize_get_cim',  
  364. $cim,  
  365. $this 
  366. ); 
  367.  
  368. /** 
  369. * Get saved customer information manager profile id. 
  370. * 
  371. * @since 1.0.0 
  372. * @param int $user_id The user Id. 
  373. * @return string The CIM profile Id. 
  374. */ 
  375. public function get_cim_profile_id( $member ) { 
  376. $cim_profile_id = $member->get_gateway_profile( 
  377. self::ID,  
  378. 'cim_profile_id' 
  379. ); 
  380.  
  381. return apply_filters( 
  382. 'ms_gateway_authorize_get_cim_profile_id',  
  383. $cim_profile_id,  
  384. $member,  
  385. $this 
  386. ); 
  387.  
  388. /** 
  389. * Get saved customer information manager payment profile id. 
  390. * 
  391. * @since 1.0.0 
  392. * @param int $user_id The user Id. 
  393. * @return string The CIM payment profile Id. 
  394. */ 
  395. public function get_cim_payment_profile_id( $member ) { 
  396. $cim_payment_profile_id = $member->get_gateway_profile( 
  397. self::ID,  
  398. 'cim_payment_profile_id' 
  399. ); 
  400.  
  401. return apply_filters( 
  402. 'ms_gateway_authorize_get_cim_payment_profile_id',  
  403. $cim_payment_profile_id,  
  404. $member,  
  405. $this 
  406. ); 
  407.  
  408. /** 
  409. * Save CIM profile IDs. 
  410. * 
  411. * @since 1.0.0 
  412. * @param MS_Model_Member $member The member to save CIM IDs. 
  413. * @param string $cim_profile_id The CIM profile ID to save. 
  414. * @param string $cim_payment_profile_id The CIM payment profile ID to save. 
  415. */ 
  416. protected function save_cim_profile( $member, $cim_profile_id, $cim_payment_profile_id ) { 
  417. $member->set_gateway_profile( 
  418. self::ID,  
  419. 'cim_profile_id',  
  420. $cim_profile_id 
  421. ); 
  422. $member->set_gateway_profile( 
  423. self::ID,  
  424. 'cim_payment_profile_id',  
  425. $cim_payment_profile_id 
  426. ); 
  427.  
  428. $this->save_card_info( $member ); 
  429. $member->save(); 
  430.  
  431. do_action( 
  432. 'ms_gateway_authorize_save_cim_profile',  
  433. $member,  
  434. $cim_profile_id,  
  435. $cim_payment_profile_id,  
  436. $this 
  437. ); 
  438.  
  439. /** 
  440. * Get customer information manager profile from Authorize.net. 
  441. * 
  442. * @since 1.0.0 
  443. * 
  444. * @param MS_Model_Member $member The member. 
  445. * @return array The A.net payment profiles array structure. 
  446. */ 
  447. public function get_cim_profile( $member ) { 
  448. $cim_profiles = array(); 
  449. $cim_profile_id = $this->get_cim_profile_id( $member ); 
  450.  
  451. if ( $cim_profile_id ) { 
  452. $response = $this->get_cim()->getCustomerProfile( $cim_profile_id ); 
  453.  
  454. if ( $response->isOk() ) { 
  455. $cim_profiles = json_decode( json_encode( $response->xml->profile ), true ); 
  456.  
  457. if ( is_array( $cim_profiles ) 
  458. && ! empty( $cim_profiles['paymentProfiles'] ) 
  459. && is_array( $cim_profiles['paymentProfiles'] ) 
  460. ) { 
  461. $cim_profiles = $cim_profiles['paymentProfiles']; 
  462.  
  463. return apply_filters( 
  464. 'ms_gateway_authorize_get_cim_profile',  
  465. $cim_profiles,  
  466. $this 
  467. ); 
  468.  
  469. /** 
  470. * Creates Authorize.net CIM profile for current user. 
  471. * 
  472. * @since 1.0.0 
  473. * @param MS_Model_Member $member The member to create CIM profile to. 
  474. */ 
  475. protected function create_cim_profile( $member ) { 
  476. do_action( 
  477. 'ms_gateway_authorize_create_cim_profile_before',  
  478. $member,  
  479. $this 
  480. ); 
  481.  
  482. $this->load_authorize_lib(); 
  483. $customer = new M2_AuthorizeNetCustomer(); 
  484. $customer->merchantCustomerId = $member->id; 
  485. $customer->email = $member->email; 
  486. $customer->paymentProfiles[] = $this->create_cim_payment_profile(); 
  487.  
  488. $response = $this->get_cim()->createCustomerProfile( $customer ); 
  489.  
  490. if ( $response->isError() ) { 
  491. MS_Helper_Debug::log( $response ); 
  492.  
  493. // Duplicate record, delete the old one. 
  494. if ( 'E00039' == $response->xml->messages->message->code ) { 
  495. $cim_profile_id = str_replace( 'A duplicate record with ID ', '', $response->xml->messages->message->text ); 
  496. $cim_profile_id = (int) str_replace( ' already exists.', '', $cim_profile_id ); 
  497.  
  498. $this->get_cim()->deleteCustomerProfile( $cim_profile_id ); 
  499.  
  500. // Try again 
  501. $this->create_cim_profile( $member ); 
  502. return; 
  503. } else { 
  504. throw new Exception( 
  505. __( 'Payment failed due to CIM profile not created: ', 'membership2' ) . $response->getMessageText() 
  506. ); 
  507.  
  508. $cim_profile_id = $response->getCustomerProfileId(); 
  509. $cim_payment_profile_id = $response->getCustomerPaymentProfileIds(); 
  510. $this->save_cim_profile( $member, $cim_profile_id, $cim_payment_profile_id ); 
  511.  
  512. /** 
  513. * Updates CIM profile by adding a new credit card. 
  514. * 
  515. * @since 1.0.0 
  516. * @param MS_Model_Member $member The member to update CIM profile. 
  517. */ 
  518. public function update_cim_profile( $member ) { 
  519. do_action( 
  520. 'ms_gateway_authorize_update_cim_profile_before',  
  521. $member,  
  522. $this 
  523. ); 
  524.  
  525. $cim_profile_id = $this->get_cim_profile_id( $member ); 
  526. $cim_payment_profile_id = $this->get_cim_payment_profile_id( $member ); 
  527.  
  528. if ( empty( $cim_payment_profile_id ) ) { 
  529. $response = $this->get_cim()->createCustomerPaymentProfile( 
  530. $cim_profile_id,  
  531. $this->create_cim_payment_profile() 
  532. ); 
  533. $cim_payment_profile_id = $response->getCustomerPaymentProfileIds(); 
  534. } else { 
  535. $response = $this->get_cim()->updateCustomerPaymentProfile( 
  536. $cim_profile_id,  
  537. $cim_payment_profile_id,  
  538. self::create_cim_payment_profile() 
  539. ); 
  540.  
  541. // If the error is not due to a duplicate customer payment profile. 
  542. if ( $response->isError() && 'E00039' != $response->xml->messages->message->code ) { 
  543. throw new Exception( 
  544. __( 'Payment failed due to CIM profile not updated: ', 'membership2' ) . $response->getMessageText() 
  545. ); 
  546.  
  547. $this->save_cim_profile( $member, $cim_profile_id, $cim_payment_profile_id ); 
  548.  
  549. /** 
  550. * Creates CIM payment profile and fills it with posted credit card data. 
  551. * 
  552. * @since 1.0.0 
  553. * @return M2_AuthorizeNetPaymentProfile The instance of AuthorizeNetPaymentProfile class. 
  554. */ 
  555. protected function create_cim_payment_profile() { 
  556. $this->load_authorize_lib(); 
  557.  
  558. $payment = new M2_AuthorizeNetPaymentProfile(); 
  559.  
  560. // billing information 
  561. $payment->billTo->firstName = substr( trim( filter_input( INPUT_POST, 'first_name' ) ), 0, 50 ); 
  562. $payment->billTo->lastName = substr( trim( filter_input( INPUT_POST, 'last_name' ) ), 0, 50 ); 
  563. $payment->billTo->company = substr( trim( filter_input( INPUT_POST, 'company' ) ), 0, 50 ); 
  564. $payment->billTo->address = substr( trim( filter_input( INPUT_POST, 'address' ) ), 0, 60 ); 
  565. $payment->billTo->city = substr( trim( filter_input( INPUT_POST, 'city' ) ), 0, 40 ); 
  566. $payment->billTo->state = substr( trim( filter_input( INPUT_POST, 'state' ) ), 0, 40 ); 
  567. $payment->billTo->zip = substr( trim( filter_input( INPUT_POST, 'zip' ) ), 0, 20 ); 
  568. $payment->billTo->country = substr( trim( filter_input( INPUT_POST, 'country' ) ), 0, 60 ); 
  569. $payment->billTo->phoneNumber = substr( trim( filter_input( INPUT_POST, 'phone' ) ), 0, 25 ); 
  570.  
  571. // card information 
  572. $payment->payment->creditCard->cardNumber = preg_replace( '/\D/', '', filter_input( INPUT_POST, 'card_num' ) ); 
  573. $payment->payment->creditCard->cardCode = trim( filter_input( INPUT_POST, 'card_code' ) ); 
  574. $payment->payment->creditCard->expirationDate = sprintf( 
  575. '%02d-%04d',  
  576. filter_input( INPUT_POST, 'exp_month', FILTER_VALIDATE_INT ),  
  577. filter_input( INPUT_POST, 'exp_year', FILTER_VALIDATE_INT ) 
  578. ); 
  579.  
  580. return apply_filters( 
  581. 'ms_gateway_authorize_create_cim_payment_profile',  
  582. $payment,  
  583. $this 
  584. ); 
  585.  
  586. /** 
  587. * Initializes and returns Authorize.net CIM transaction object. 
  588. * 
  589. * @since 1.0.0 
  590. * @param MS_Model_Member $member The member. 
  591. * @return M2_AuthorizeNetTransaction The instance of AuthorizeNetTransaction class. 
  592. */ 
  593. protected function get_cim_transaction( $member ) { 
  594. $this->load_authorize_lib(); 
  595.  
  596. $cim_profile_id = $this->get_cim_profile_id( $member ); 
  597. $cim_payment_profile_id = $this->get_cim_payment_profile_id( $member ); 
  598.  
  599. if ( empty( $cim_profile_id ) || empty( $cim_payment_profile_id ) ) { 
  600. throw new Exception( __( 'CIM Payment profile not found', 'membership2' ) ); 
  601.  
  602. $transaction = new M2_AuthorizeNetTransaction(); 
  603. $transaction->customerProfileId = $cim_profile_id; 
  604. $transaction->customerPaymentProfileId = $cim_payment_profile_id; 
  605.  
  606. // Include the card code if the secure-cc flag is enabled! 
  607. if ( lib3()->is_true( $this->secure_cc ) ) { 
  608. if ( ! empty( $_POST['card_code'] ) ) { 
  609. $transaction->cardCode = $_POST['card_code']; 
  610.  
  611. return apply_filters( 
  612. 'ms_gateway_authorize_get_cim_transaction',  
  613. $transaction,  
  614. $member,  
  615. $this 
  616. ); 
  617.  
  618. /** 
  619. * Verify required fields. 
  620. * 
  621. * @since 1.0.0 
  622. * @return boolean True if it is configured. 
  623. */ 
  624. public function is_configured() { 
  625. $is_configured = true; 
  626. $required = array( 'api_login_id', 'api_transaction_key' ); 
  627.  
  628. foreach ( $required as $field ) { 
  629. $value = $this->$field; 
  630. if ( empty( $value ) ) { 
  631. $is_configured = false; 
  632. break; 
  633.  
  634. return apply_filters( 
  635. 'ms_gateway_authorize_is_configured',  
  636. $is_configured,  
  637. $this 
  638. ); 
.