By Jason McMahon on Wednesday, 29 June 2022
Posted in General Issues
Replies 1
Likes 0
Views 350
Votes 0
On my client old site.. soon. to be retetiured were are using the PayPLans API to create 'child accounts'

Basically, when someone subscribes to a 'team membership' field appear in their joomlas profile to list email, and name of teanm members. Wen they save their account a plugin fires the following code snippet which

1) creates the child account
2) uses the payplans API to assign them the child account
3) Creates the invoice, transaction and activates the account.

It works nicely.. however this was Version 3. I am concerned that you no longer have API docs and I will have this functionality removed which will be a MASSIVE show stopper

Here is the code with PayPlans old API calls which I HOPE will still work.. if you could confirm this is the case. Yiour code starts about half way down. Will these API calls still work?


if ($data['team_member_name_'.$x] && $data['team_member_id_'.$x] < 1) {
$model = new UsersModelRegistration();
$type = 0;
$username = $data['team_member_email_' . $x];
$password = 'abcd1234';
$name = $data['team_member_name_' . $x];
$email = $data['team_member_email_' . $x];
$sendEmail = 0;
$activation = 0;

$userdata = array('username' => $username,
'name' => $name,
'email1' => $email,
'password1' => $password, // First password field
'password2' => $password, // Confirm password field
'sendEmail' => $sendEmail,
'activation' => $activation,
'block' => "0",
'groups' => array("2", "19"));

$response = $model->register($userdata);

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id');
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('username')." = ".$db->quote($email));

// Reset the query using our newly populated query object.
$db->setQuery($query);
$newId = $db->loadResult();

$data['team_member_id_'. $x] = $newId;

$plan = PayplansPlan::getInstance(10);
$order = $plan->subscribe($newId)
->save();

$invoice = $order->createInvoice();

//apply 100% discount
$modifier = PayplansModifier::getInstance();
$modifier->set('message', 'Free team membership for corporate team member')
->set('invoice_id', $invoice->getId())
->set('user_id', $invoice->getBuyer())
->set('type', 'assign_plan')
->set('amount', -100) // 100 percent Discount, discount must be negative
->set('percentage', true)
->set('frequency', PayplansModifier::FREQUENCY_ONE_TIME)
->set('serial', PayplansModifier::FIXED_DISCOUNT)
->save();

$invoice->refresh()->save();

// create a transaction with 0 amount
$transaction = PayplansTransaction::getInstance();
$transaction->set('user_id', $invoice->getBuyer())
->set('invoice_id', $invoice->getId())
->set('message', 'COM_PAYPLANS_TRANSACTION_CREATED_FOR_ASSIGN_PLAN_TO_USER')
->save();
}
The Payplans 3.x code is no longer compatible with Payplans 4.x since we revamped the code structure.

But you can refer this assign a plan to a specific user function code from this file JoomlaFolder/administrator/components/com_payplans/controllers/user.php (applyPlan function)

Hope this will help.
·
Thursday, 30 June 2022 10:57
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post