Skip to Content Skip to Menu

[SOLVED] DB Connection Help Need on PHP Code Trigger for CB Subs

10 years 8 months ago - 10 years 7 months ago #241791 by prestoproducts
I am attempting to take the payment method from the notifications table and add it to a CB Field for the associated user. Can you please help me configure the PHP script for the CB Trigger?

I see the table #__cbsubs_notifications, and in it we have a payment_method column. Ultimately I need to have a record of the current card name that they have on file with Authorize.net.

Here is my PHP plan:
Code:
//need to have you assist with connecting to #__cbsubs_notifications //after connecting I need to know the best way to pull the current payment method out from user’s notifications in cbsubs and set it as the variable $payment_method //once I have determined the current $payment_method then I will apply it to cb_payment_method $user = cbUser::getUserDataInstance( '[user_id]' ); $user->set( 'cb_payment_method', $payment_method ); $user->store();

The second part to this question is which trigger gets fired every time that the credit card is updated? Should I run the check after each logout so that I know whether or not it was updated during that user session? Or, is there a CBSubs trigger that fires at each update?
Last edit: 10 years 7 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8282
  • Karma: 1443
10 years 8 months ago #241848 by krileon
Is there a reason you need to store it to a field column in the database? You can dynamically pull this value using CB Query Field by querying the database.

The below query for example (compatible with CB Query Field) will pull the last notification for the user and select the payment method.

Code:
SELECT `payment_method` FROM `#__cbsubs_notifications` WHERE `user_id` = '[user_id]' ORDER BY `time_received` DESC LIMIT 1

I however suggest grabbing the basket instead of the notification. Please see the below example query to do this.

Code:
SELECT `payment_method` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[user_id]' ORDER BY `time_initiated` DESC LIMIT 1


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 or Create an account to join the conversation.

10 years 8 months ago #241873 by prestoproducts
Replied by prestoproducts on topic DB Connection Help Need on PHP Code Trigger for CB Subs
Thank you Kyle, I will try this out and let you know if I have any trouble. I am still a bit perplexed about the best trigger to use to fire this script. Let me give you a bit more background on the ultimate goal...

We are collecting payments with Authorize.net. We keep the last 4 digits from the card as well as the name and expiration date in a database outside JOomla.

If a user logs into our Joomla site and updates their card on file with Authorize.net I need to be able to know that the update occurred and send the information out to the master database.

So, first of all is this feasible? If not, what are the potential holes? If it is feasible, should I just run the check at each session end for the user?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8282
  • Karma: 1443
10 years 8 months ago - 10 years 8 months ago #241900 by krileon
I suggesting using the CBSubs SQL Actions integration and push the info straight to your other database when the plan becomes active. This way you don't need to deal with trigger management. You can then get the last couple of digits from the payer_id column of the CBSubs basket database table, which should be something like "XXXX XXXX XXXX 1111". Example query as follows.

Code:
SELECT `payer_id` FROM `#__cbsubs_payment_baskets` WHERE `user_id` = '[user_id]' ORDER BY `time_initiated` DESC LIMIT 1

The above would grab the payer_id of their most recent basket. You'd plug that into a CB Query Field then substitute it into your query to your external database. Normally you'd put it all in 1 query, but since your other database is separate from Joomla you can't query to both connections at once.


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.
Last edit: 10 years 8 months ago by krileon.

Please Log in or Create an account to join the conversation.

10 years 8 months ago #242000 by prestoproducts
Replied by prestoproducts on topic DB Connection Help Need on PHP Code Trigger for CB Subs
Thank you, I believe this has pointed me in the right direction for development. Any suggestion on pulling the expiration date? The only place I see it listed is in the "raw_data" column of #__cbsubs_notifications. The problem there is that it is all wrapped up in the POST data. If this is the only place that it exists, do you have any idea of best practice to strip away the excess so that I can pull the expiration date?

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
10 years 8 months ago #242009 by nant

prestoproducts wrote: Thank you, I believe this has pointed me in the right direction for development. Any suggestion on pulling the expiration date? The only place I see it listed is in the "raw_data" column of #__cbsubs_notifications. The problem there is that it is all wrapped up in the POST data. If this is the only place that it exists, do you have any idea of best practice to strip away the excess so that I can pull the expiration date?


See latest mega tutorial here:

www.joomlapolis.com/support/tutorials/107-use-cases/18405-family-plan-membership-part-1

There are some scripts that get the expiration date from the database table - but you can also use a CB Field action to push the expiration date in a CB Field.
The following user(s) said Thank You: krileon, prestoproducts

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum