);
}
- /**
- * processMemberRenewal
- *
- * @param int $account_id Id of the account
- * @param int $invoice_id Id of the invoice
- * @param float $amount Amount of the total invoice
- * @param array $employees Array of employees
- *
- * @access public
- * @return array
- */
- public function processMemberRenewal( $account_id, $invoice_id, $amount, $employees = array() )
+ public function processPayment()
{
$errors = array();
// Get the selected credit card processor type
break;
}
-
// Get the credit card input
$cardData = filter_var_array(
$_REQUEST,
} else {
$errors[] = 'You did not supply all required credit card information correctly.';
}
-
if (count($errors) == 0) {
// Determine the directory of the payment processor to load and instantiate it.
$CcProcessor = new PaymentGateway( $account );
}
+ // TODO: Need to update the $invoice_id to something better for billing.
$payment = array(
'name' => $this->config['settings']['company_name'], // Company Name
'charge' => $amount, // Total charges
'ccnumb' => $cardData['cc_numb'], // Card Number
'ccexp' => $cardData['cc_exp'], // Expiration Date
'cccode' => $cardData['cc_cvv'], // CCV - security code
- 'invoice' => 'billing-'.$invoice_id // Invoice # is "reg-" plus cart ID
+ 'invoice' => 'billing-'//.$invoice_id // Invoice # is "reg-" plus cart ID
);
// Now try to run the card processor
// If successful submission - say we're complete
if ( is_array( $ccResult ) && isset( $ccResult['status'] ) && $ccResult['status'] == 1 ) {
- // Need to record the payment
-
- // Set transaction_time to current time.
- $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
- // Create new payment.
- $payment_id = $this->createPayment( $account_id, $amount );
- // Record the payment.
- $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
-
- // $errors[] = $ccResult['statusText'];
- // $errors[] = $ccResult['description'];
-
- // Need to update the members account renewal_date
- $this->wpdb->update(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
- array( 'renewal_date' => date( 'Y-m-d' ) ),
- array( 'id' => $account_id ),
- array( '%s' ),
- array( '%d' )
+ $result = array(
+ 'status' => 1,
+ 'errors' => array(),
+ 'ccResult' => $ccResult
);
- // Need to update any employees renewal dates
- if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) {
- foreach ( $employees as $employee ) {
- $this->wpdb->update(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
- array( 'renewal_date' => date( 'Y-m-d' ) ),
- array( 'id' => $employee ),
- array( '%s' ),
- array( '%d' )
- );
- }
- }
}
+ } else {
+ $result = array(
+ 'status' => 0,
+ 'errors' => $errors
+ );
+ }
+ return $result;
+ }
+
+ /**
+ * processMemberRenewal
+ *
+ * @param int $account_id Id of the account
+ * @param int $invoice_id Id of the invoice
+ * @param float $amount Amount of the total invoice
+ * @param array $employees Array of employees
+ *
+ * @access public
+ * @return array
+ */
+ public function processMemberRenewal( $account_id, $invoice_id, $amount, $employees = array() )
+ {
+ $result = $this->processPayment();
+
+ if ( $result['status'] === 1 ) {
+
+ // Need to record the payment
+ // Set transaction_time to current time.
+ $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
+
+ // Create new payment.
+ $payment_id = $this->createPayment( $account_id, $amount );
+
+ // Record the payment.
+ $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
+
+ // $errors[] = $ccResult['statusText'];
+ // $errors[] = $ccResult['description'];
+
+ // Need to update the members account renewal_date
+ $this->wpdb->update(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ array( 'renewal_date' => date( 'Y-m-d' ) ),
+ array( 'id' => $account_id ),
+ array( '%s' ),
+ array( '%d' )
+ );
+
+ // Need to update any employees renewal dates
+ if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) {
+ foreach ( $employees as $employee ) {
+ $this->wpdb->update(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ array( 'renewal_date' => date( 'Y-m-d' ) ),
+ array( 'id' => $employee ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+ $errors = $result['errors'];
+
+ } else {
+ $errors = $result['errors'];
}
return $errors;
}
+ public function makePayment( $account_id, $invoices, $amount )
+ {
+ $result = $this->processPayment();
+ if ( $result['status'] === 1 ) {
+
+ // Need to record the payment.
+ // Set transaction_time to current time.
+ $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
+
+ // Create new payment.
+ $payment_id = $this->createPayment( $account_id, $amount );
+
+ // Record the payment.
+ $this->recordPayment( $payment_id, $account_id, $amount, $invoices );
+
+ $errors = $result['errors'];
+ } else {
+ $errors = $result['errors'];
+ }
+ }
+
/**
* removeInvoiceById
*