Skip to Content Skip to Menu

Background Understanding Needed on Basket Form Values

10 years 8 months ago #241330 by prestoproducts
When an invoice is submitted to create a basket from CB Subs, I see the following form (as one such example):
Code:
<form action="../pluginclass?plugin=cbpaidsubscriptions&amp;cbpgacctno=1&amp;cbppdtback=58fdf0067990ba782af087df8ac663b7&amp;cbpbasket=24&amp;cbpshopuser=691ddb877c4e9aacfac81fb555d04cb5&amp;result=payform&amp;cbpid=cbp5301234bd41cb277123612" method="post"> <input type="button" class="button cbpaidjsSubmit cbpaidCCbuttonInput" name="BPay" value="Single Button Submit" alt="Pay with your credit card" title="Pay with your credit card" /> <input type="hidden" name="basket" value="23" /> <input type="hidden" name="shopuser" value="691ddb877c4e9aacfac81fb555d04cb5" /> </form>

Upon investigation of the database, I see that the baskets exist in #__cbsubs_payment_baskets. My goal is to be able to manually create the basket and associated fields so that I can directly link the user to the basket and eliminate 1 step (the invoice) in the workflow.

I have seen posts on the forum saying that this cannot be done, but I know that it is possible. I know this because I have found an example online of a workable site doing so. I will gladly PM a link to the site if you would like to review it.

Ok, so the columns and form items I need to better understand are:

1) cbppdtback : this is in the form action URL. How is this generated and what are the key connections to create a basket?

2) cbpshopuser : this is in the form action URL. How is this generated and what are the key connections to create a basket?

3) cbpid : this is in the form action URL. I see that this matches the shared_secret column in the database table. How is this generated and what are the key connections to create a basket?

I believe that with a bit more digging I will be able to come up with a good fix. Thank you for your time.

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

10 years 8 months ago #241338 by prestoproducts
Replied by prestoproducts on topic Background Understanding Needed on Basket Form Values
Ok, so I managed to find out how “cbpid” it appears to be a randomly generated value that starts with “cbp.” To create “cbpshopuser” it looks like we just take the user id, place it next to the “cbpid” and then run it through MD5 hashing. Good, no problem there from what I can tell.

This leaves the “cbppdtback” value to be determined. From what I can see, this is the function that is generating the value:
Code:
/** * Computes a simple hash for the payment pdtback parameter * * @param int $basketId Payment basket id * @return string Unique hash */ protected function hashPdtBack( $basketId = null ) { if ( ( $this->_urlHashType === 2 ) || ( ( $this->_urlHashType === 1 ) && $basketId ) ) { global $_CB_framework; $secret = $_CB_framework->getCfg( 'secret' ); $site = $_CB_framework->getCfg( 'live_site' ); $site = rtrim( ltrim( $site, 'htpsHTPS:/' ), '0123456789:/' ); $clear = $secret . $this->getPayName() . 'return' . $site . $basketId; return md5( $clear ); } return ''; }
Is that it? If so, I have found the “secret” and “live_site” by posting the following code in my profile:
Code:
<?php global $_CB_framework; $secret = $_CB_framework->getCfg( 'secret' ); $site = $_CB_framework->getCfg( 'live_site' ); $trimsite = rtrim( ltrim( $site, 'htpsHTPS:/' ), '0123456789:/' ); echo 'Secret: '.$secret.'<br>'; echo 'Site: '.$site.'<br>'; echo 'Trimmed Site: '.$trimsite.'<br>'; ?>
I then took the $secret value, placed it next to the pay name (authorizenet), added the word “return,” then comes the trimmed site value and finally the basket id (23 in this case). I ran that value through an MD5 hash, but it is not matching…

Please help me determine where I went wrong and how I can fix this. Thank you for your time.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago #241365 by krileon
All of that is generated internally. It's not a simple process. Calling getShowBasketUrl from a basket object will give you its correctly structured URL, but it doesn't do anything if the basket doesn't exist. The basket is generated internally based off plan selection and various other information using createPaymentBasket, which is called from internal function createAndFillCreteSubscriptionsItems. The usage continues to bubble up through CBSubs.

I've no idea how the site you got this from is doing it, but I doubt that's all there is to it. They had to have modified it to generate the baskets or something of the sort, because you can't create a basket from a simple URL as it has no information on what the basket is for. Trying to access a basket that doesn't exist will throw something about the basket doesn't login or doesn't exist.


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 #241382 by prestoproducts
Replied by prestoproducts on topic Background Understanding Needed on Basket Form Values
Thank you for the reply. Yes, I have seen the error stating that the basket does not exist. I am planning on creating the basket manually with a CB Auto Action after registration. I will then send the user to that basket for the second step.

Ultimately I just need to know how I can recreate the cbppdtback value when I link to the basket. Can you please let me know if I am on the right track with the second reply and if so how I can obtain the correct value?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago - 10 years 8 months ago #241395 by krileon
Load the basket and call the basket url function after you've created it. Example as follows.

Code:
$paymentBasket = new cbpaidPaymentBasket(); $paymentBasket->load( BASKET_ID_HERE ); $basketUrl = $paymentBasket->getShowBasketUrl();

If you're absolutely sure the last basket added is the one you want you can even just grab the most recent basket based off user. Example as follows.

Code:
$paymentBasket = cbpaidPaymentBasket::getInstanceBasketOfUser( USER_ID_HERE, false ) $basketUrl = $paymentBasket->getShowBasketUrl();

Now we can go even further. We can grab the most recent basket based off a plan id. Example as follows.

Code:
$paymentBasket = new cbpaidPaymentBasket(); $paymentBasket->loadLatestBasketOfUserPlanSubscription( USER_ID_HERE, PLAN_ID_HERE ); $basketUrl = $paymentBasket->getShowBasketUrl();

Lets go deeper! Now we can even grab it based off an existing subscription id for a plan for a user. Example as follows.

Code:
$paymentBasket = new cbpaidPaymentBasket(); $paymentBasket->loadLatestBasketOfUserPlanSubscription( USER_ID_HERE, PLAN_ID_HERE, SUBSCRIPTION_ID_HERE ); $basketUrl = $paymentBasket->getShowBasketUrl();


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 #241420 by prestoproducts
Replied by prestoproducts on topic Background Understanding Needed on Basket Form Values
I now see that
Code:
function getShowBasketUrl
will create the URL of the basket, which is what I need. I appreciate that. The last step is for me to be able to physically see this on the page (just helps me better understand).

So, where can I go input this value to see the output of
Code:
$basketUrl
?

Code:
$paymentBasket = new cbpaidPaymentBasket(); $paymentBasket->load( '23' ); $basketUrl = $paymentBasket->getShowBasketUrl();

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

Moderators: beatnantkrileon
Powered by Kunena Forum