Invoicing for recurring payments

4 years 11 months ago - 4 years 11 months ago #312153 by activha
Replied by activha on topic Invoicing for recurring payments
If we use onCPayAfterPaymentStatusUpdateEvent, what is the best global status to use ?

For instance STRIPE only sends back the Completed status for SEPA recurring payment, so Pending would not work. And on the contrary Manual Gateways can have Initiated, then Pending then Completed.

So how can we avoid to have three times the auto action running for the manual gateways and wrongly implemented payment invoice numbers ?

Also I have noticed that the invoice output only displays the [user_id] of the mod and not the one of the user.
I tried to set
$paymentBasket->set( 'user_id', $payment->get( 'for_user_id'  ) );
but this does not work. Do you have an idea to display the correct user_id ?

Please Log in to join the conversation.

4 years 11 months ago #312157 by krileon
Replied by krileon on topic Invoicing for recurring payments

If we use onCPayAfterPaymentStatusUpdateEvent, what is the best global status to use ?

For the renumbering? You don't even need to bother checking status. Just let it renumber anytime that event is called

So how can we avoid to have three times the auto action running for the manual gateways and wrongly implemented payment invoice numbers ?

It can't wrongly renumber them as it clears the number and renumbers each call. I'm not 100% sure the SET variable will even work in a Query action so be sure to test carefully.

Also I have noticed that the invoice output only displays the [user_id] of the mod and not the one of the user.

That's due to $user being passed. Try the below.
// First lets try to find and load the payment:
$payment		=	new cbpaidPayment();

$payment->load( (int) '[get_payment]' );

$isOwner		=	( (int) $payment->get( 'by_user_id' ) == (int) '[user_id]' );

if ( ( ! $isOwner ) && ( ! \CBLib\Application\Application::User( (int) '[user_id]' )->isGlobalModerator() ) ) {
	return null;
}

// Now we need the original basket for the payment:
$paymentBasket	=	new cbpaidPaymentBasket();

$paymentBasket->load( (int) $payment->get( 'payment_basket_id' ) );

$paymentUser	=	CBuser::getUserDataInstance( (int) $paymentBasket->get( 'user_id' ) );

// Finally we'll override some of the values of the basket so the basket invoice reflects the most recent payment:
$paymentBasket->set( 'time_initiated', $payment->get( 'time_created' ) );
$paymentBasket->set( 'time_updated', $payment->get( 'time_modified' ) );
$paymentBasket->set( 'time_completed', $payment->get( 'time_paid' ) );
$paymentBasket->set( 'time_completed_date', $payment->get( 'time_paid_date' ) );
$paymentBasket->set( 'time_completed_day_of_week', $payment->get( 'time_paid_day_of_week' ) );
$paymentBasket->set( 'time_completed_yearweek', $payment->get( 'time_paid_yearweek' ) );
$paymentBasket->set( 'time_completed_yearmonth', $payment->get( 'time_paid_yearmonth' ) );
$paymentBasket->set( 'time_completed_hour', $payment->get( 'time_paid_hour' ) );
$paymentBasket->set( 'proformainvoice', $payment->get( 'invoice' ) );

return $paymentBasket->displayInvoice( $paymentUser, $isOwner, false );


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

4 years 11 months ago - 4 years 11 months ago #312162 by activha
Replied by activha on topic Invoicing for recurring payments

I'm not 100% sure the SET variable will even work in a Query action so be sure to test carefully.


You were right, I tried :
SET @a = 0;
UPDATE `#__cbsubs_payments` SET `invoice` = CONCAT( SUBSTRING_INDEX( `invoice`, '-', 1 ), '-', ( @a:=@a + 1 ) ) WHERE `payment_basket_id` = [var2_id]

But it does not seem to work. I have tried on direct query to the DB and this one is ok :
SET @a = 0;
UPDATE `yq0g1_cbsubs_payments` SET `invoice` = CONCAT( SUBSTRING_INDEX( `invoice`, '-', 1 ), '-', ( @a:=@a + 1 ) ) WHERE `payment_basket_id` = '5409'

Maybe the SET in the Autoaction query ??

Please Log in to join the conversation.

4 years 11 months ago #312163 by activha
Replied by activha on topic Invoicing for recurring payments
Answering to myself : Code Autoaction does not work for Query, But Query Autoaction works fine with the code.

I guess that you should implement this kind of thing in CBsubs. So Baskets would be in fact orders, and Payments would be in fact invoices (either pending or paid, but as soon as Payment is initiated an invoice with a correct number would be displayed)

If now we could output this directly in PDF that would be perfect to have a great system :-)

Please Log in to join the conversation.

4 years 11 months ago #312170 by krileon
Replied by krileon on topic Invoicing for recurring payments
The query to increment the payment invoices is supposed to be used in a Query action where it should work fine. If it's not then split the SET and the UPDATE into 2 completely different queries using the "Add Rows" button and doing the SET first.

I guess that you should implement this kind of thing in CBsubs. So Baskets would be in fact orders, and Payments would be in fact invoices (either pending or paid, but as soon as Payment is initiated an invoice with a correct number would be displayed)

We will implement frontend payment history that matches what everyone else is doing (just a table of data, as you're doing now) and we will be reviewing a separate invoice numbering system for those payments (as you're doing with the query action). What you choose to rename things using language strings will be entirely up to you.

If now we could output this directly in PDF that would be perfect to have a great system

There is no requirement for them to be PDF. We've no plans to implement PDF generation at this time. You can use &tmpl=component&print=1 in your URL to make them print accessible.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

4 years 11 months ago #312171 by activha
Replied by activha on topic Invoicing for recurring payments
Thanks for all !

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.254 seconds

Facebook Twitter LinkedIn