Skip to content

Commit

Permalink
Merge pull request #41 from andrewlimaza/dev
Browse files Browse the repository at this point in the history
Fix initialPeriod incorrectly set
  • Loading branch information
andrewlimaza authored Oct 5, 2023
2 parents 82d3cc8 + 3df17d5 commit 641ac92
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions classes/class.pmprogateway_ccbill.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function sendToCCBill( &$order ) {

global $pmpro_currency;

$currency_code = $this->get_currency_code();
$currency_code = PMProGateway_CCBill::get_currency_code();

//get the options

Expand Down Expand Up @@ -584,7 +584,8 @@ function pmprocb_return_api_response( $code ) {
* @return int The initial period.
*/
private function get_initialPeriod( $order ) {
if ( pmpro_isLevelRecurring( $order->membership_level ) ) {
$level = $order->getMembershipLevel();
if ( pmpro_isLevelRecurring( $level ) ) {
// For recurring payments, period is billing period.
$profile_start_date = pmpro_calculate_profile_start_date( $order, 'U', true );
$period = ceil( abs( $profile_start_date - time() ) / 86400 );
Expand All @@ -593,11 +594,27 @@ private function get_initialPeriod( $order ) {
$period = min( $period, 365 );

// NOTE: We're not supporting custom trials right now. Probably can't.
} elseif ( $level->expiration_number > 0 ) {
// Get the levels expiration and convert it to days.
$expiration_date = $this->calculate_expiration_date( $level );
$order_date = date( "Y-m-d", $order->timestamp );
$period = round( ( strtotime( $expiration_date ) - strtotime( $order_date ) ) / DAY_IN_SECONDS );
} else {
// Set period to 1 for one time payments.
$period = 1;
$period = 2; //CCBill doesn't allow period values of 1.
}

return $period;
}

/**
* Convert expiration period to date to YYYY-MM-DD from level expiration settings.
*
* @param MemberOrder $order
* @return string $calculated_date The calculated date of expiration date from todays date. (i.e. 2024-01-31)
*/
public function calculate_expiration_date( $level ) {
//Convert $level->expiration_period + $level->expiration_number to a date.
$expiration_date = date( "Y-m-d", strtotime( "+ " . $level->expiration_number . " " . $level->expiration_period, current_time( "timestamp" ) ) );
return $expiration_date;
}
}

0 comments on commit 641ac92

Please sign in to comment.