Created
February 4, 2015 15:29
-
-
Save JudeRosario/d0b9072e8479fb04b905 to your computer and use it in GitHub Desktop.
Membership Authorize.NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function process_purchase() { | |
global $M_options; | |
if ( empty( $M_options['paymentcurrency'] ) ) { | |
$M_options['paymentcurrency'] = 'USD'; | |
} | |
if ( ! is_ssl() ) { | |
wp_die( __( 'You must use HTTPS in order to do this', 'membership' ) ); | |
exit; | |
} | |
// fetch subscription and pricing | |
$sub_id = filter_input( INPUT_POST, 'subscription_id', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) ); | |
$this->_subscription = Membership_Plugin::factory()->get_subscription( $sub_id ); | |
$pricing = $this->_subscription->get_pricingarray(); | |
if ( ! $pricing ) { | |
status_header( 404 ); | |
exit; | |
} | |
// apply a coupon | |
$coupon = membership_get_current_coupon(); | |
if ( $coupon && $coupon->valid_for_subscription( $this->_subscription->id ) ) { | |
$pricing = $coupon->apply_coupon_pricing( $pricing ); | |
} | |
// fetch member | |
$user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id']; | |
$this->_member = Membership_Plugin::factory()->get_member( $user_id ); | |
// fetch CIM user and payment profiles info | |
// pay attention that CIM can't handle recurring transaction, so we need | |
// to use standard ARB aproach and full cards details | |
$has_serial = in_array( 'serial', wp_list_pluck( $pricing, 'type' ) ); | |
if ( ! $has_serial ) { | |
$this->_cim_payment_profile_id = trim( filter_input( INPUT_POST, 'profile' ) ); | |
if ( ! empty( $this->_cim_payment_profile_id ) ) { | |
$this->_cim_profile_id = get_user_meta( $this->_member->ID, 'authorize_cim_id', true ); | |
if ( $this->_cim_profile_id ) { | |
$response = $this->_get_cim()->getCustomerPaymentProfile( $this->_cim_profile_id, $this->_cim_payment_profile_id ); | |
if ( $response->isError() ) { | |
$this->_cim_payment_profile_id = false; | |
} | |
} | |
} | |
} | |
// process payments | |
$first_payment = false; | |
$started = new DateTime(); | |
$this->_payment_result = array( 'status' => '', 'errors' => array() ); | |
$this->_transactions = array(); | |
for ( $i = 0, $count = count( $pricing ); $i < $count; $i ++ ) { | |
if ( $first_payment === false && $pricing[$i]['amount'] > 0 ) { | |
$first_payment = $pricing[$i]['amount']; | |
} | |
switch ( $pricing[$i]['type'] ) { | |
case 'finite': | |
//Using AIM for onetime payment | |
$this->_transactions[] = $this->_process_nonserial_purchase( $pricing[$i], $started ); | |
/*//Call ARB with only one recurrency for each subscription level. | |
$this->_transactions[] = $this->_process_serial_purchase( $pricing[$i], $started, 1, $unit = 'months', 12 ); | |
$interval = self::_get_period_interval_in_date_format( $pricing[$i]['unit'] ); | |
$started->modify( sprintf( '+%d %s', $pricing[$i]['period'], $interval ) );*/ | |
break; | |
case 'indefinite': | |
$this->_transactions[] = $this->_process_nonserial_purchase( $pricing[$i], $started ); | |
break 2; | |
case 'serial': | |
//Call ARB with no end date (an ongoing subscription). | |
$this->_transactions[] = $this->_process_serial_purchase( $pricing[$i], $started, 12 ); | |
break 2; | |
} | |
if ( $this->_payment_result['status'] == 'error' ) { | |
$this->_rollback_transactions(); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment