Skip to content

Commit

Permalink
Fix issues and deprecated warnings for PMPro 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlimaza committed Oct 3, 2024
1 parent b8af627 commit 7e4b85a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions classes/class.pmprogateway_payfast.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,16 @@ function sendToPayFast( &$order ) {
$order->cardtype = "";
$order->ProfileStartDate = date_i18n( 'Y-m-d', current_time( 'timestamp' ) );

// Get the level amount so we can set the initial payment amount.
$level = $order->getMembershipLevelAtCheckout();

// taxes on initial payment
$initial_payment = $order->InitialPayment;
$initial_payment = $order->subtotal;
$initial_payment_tax = $order->getTaxForPrice( $initial_payment );
$initial_payment = round( (float) $initial_payment + (float) $initial_payment_tax, 2 );

// taxes on the amount
$amount = $order->PaymentAmount;
$amount = empty( $level->billing_amount ) ? 0 : $level->billing_amount;
$amount_tax = $order->getTaxForPrice( $amount );
$order->subtotal = $amount;
$amount = round( (float) $amount + (float) $amount_tax, 2 );
Expand All @@ -350,26 +353,28 @@ function sendToPayFast( &$order ) {
$payfast_url = 'https://www.payfast.co.za/eng/process';
}

$user = get_userdata( $order->user_id );
$nameparts = pnp_split_full_name( $order->billing->name );

$data = array(
'merchant_id' => $merchant_id,
'merchant_key' => $merchant_key,
'return_url' => pmpro_url( 'confirmation', '?level=' . $order->membership_level->id ),
'cancel_url' => pmpro_url( 'levels' ),
'notify_url' => admin_url( 'admin-ajax.php' ) . '?action=pmpro_payfast_itn_handler',
'name_first' => $order->FirstName,
'name_last' => $order->LastName,
'email_address' => $order->Email,
'name_first' => empty( $nameparts['fname'] ) ? '' : $nameparts['fname'],
'name_last' => empty( $nameparts['lname'] ) ? '' : $nameparts['lname'],
'email_address' => $user->user_email,
'm_payment_id' => $order->code,
'amount' => $initial_payment,
'item_name' => html_entity_decode( substr( $order->membership_level->name . ' at ' . get_bloginfo( 'name' ), 0, 99 ) ),
'custom_int1' => $order->user_id,
);

$cycles = $order->membership_level->billing_limit;

if( ! empty( $order->BillingFrequency ) ) {
if( ! empty( $level->cycle_number ) ) {
// convert PMPro cycle_number and period into a PayFast frequency
switch ( $order->BillingPeriod ) {
switch ( $level->cycle_period ) {
case 'Day':
$frequency = '1';
break;
Expand All @@ -387,10 +392,9 @@ function sendToPayFast( &$order ) {

// Add subscription data
if ( ! empty( $frequency ) ) {
// $data['m_subscription_id'] = /*$order->getRandomCode()*/$order->code;
$data['custom_str1'] = $order->ProfileStartDate;
$data['custom_str1'] = pmpro_calculate_profile_start_date( $order, 'Y-m-d' );
$data['subscription_type'] = 1;
$data['billing_date'] = apply_filters( 'pmpro_profile_start_date', $order->ProfileStartDate, $order );
$data['billing_date'] = apply_filters( 'pmpro_profile_start_date', $data['custom_str1'], $order );
$data['recurring_amount'] = $amount;
$data['frequency'] = $frequency;
$data['cycles'] = $cycles == 0 ? 0 : $cycles + 1;
Expand All @@ -407,7 +411,6 @@ function sendToPayFast( &$order ) {
$order->status = 'token';
$order->payment_transaction_id = $order->code;
$order->subscription_transaction_id = $order->code;
$order->subtotal = $order->InitialPayment;
$order->tax = $initial_payment_tax;
$order->total = $initial_payment;

Expand Down

0 comments on commit 7e4b85a

Please sign in to comment.