MyBB Community Forums

Full Version: Storing award id in a cookie
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey ppl,

I have created a forum wadakela.xyz. I have added newPoints Awards System in it. Which is integrated with CoinPayments for user to buy it.
img: https://i.imgur.com/sI7Edly.png

Now, for example I have 5 awards and user buys 3rd one. I have scripted files which send an email and PM to me notifying that "this" user has purchased an award with ''this award ID'' when the user gets on success (callback from coinpayment) page.

imgs: https://imgur.com/a/fzR1qQl

Initially, when it was not integrated with coinpayments, I used POST method to get the award ID from the form when someone clicks BUY button through awards page which actually was working fine. I could get the proper id using this code.
//awards page
<input type="hidden" name="award" value="{$award['aid']}">

//success page
$award_id = $POST['award'];

Now that it is integrated with CoinPayments, it's not going to the success.php directly so POST method isn't working. If I'm not wrong, I can get the award id in the success.php via cookies (or sessions maybe?). But, I'm failing to store award ID in a cookie.

As we know, it's now like this:
-awards page -> coinpayments site -> success page.

To get award ID from awards page to success page, I tried the following code to store award ID into the cookie:
(guided by this topic: https://community.mybb.com/thread-115261.html)
//in awards page
my_setcookie("award",$award['aid']);

//in the form
<input type="hidden" name="award" value="{$award['aid']}">

//ALSO TRIED
<input type="hidden" name="{$mybb->cookies['award']}" value="{$award['aid']}">



....processing with coinpayments....



//in success (callback) page
$award_id = $mybb->cookies['award'];

echo $award_id;  //pm + email actually.

my_unsetcookie("award");

in success page, $award_id Always returns "5". Maybe because there are 5 awards listed?

Other than this, the whole process is very smooth and working as intended. What I want to do is to store proper award ID in the cookie.

I'd appreciate if one could help me with this. And if there's any alternate to achieve this, I'd like to know about it as well.

And also, I really need to get it done by today.. 

If you need more information, please let me know.

Thank you. Smile

Well, seeing no response from anybody. I would like to know if one requires any additional information or Am I missing something?

Just to add in my previous reply: Newpoints Awards System uses NewPoints and OUGC Awards to extend them. Basically, I'm trying to get award ID (aid) of OUGC awards from awards page to the success page. Which I need help with storing award ID in a cookie..

Waiting for response! Thank you.
As far as I understand it you need to send the award information to the Coinbase API and once successful the API should be returning the item or cart information back. But I have never worked with payment systems before.

Can you link to the API or script you use for payments? The _Newpoints Awards_ plugin only ships with Newpoints support.

As an alternative, have you thought about using the following plugin?:
https://forums.mybb-plugins.com/Thread-P...redits-2-0
(2020-05-22, 04:44 PM)Omar G. Wrote: [ -> ]As far as I understand it you need to send the award information to the Coinbase API and once successful the API should be returning the item or cart information back. But I have never worked with payment systems before.

Can you link to the API or script you use for payments? The _Newpoints Awards_ plugin only ships with Newpoints support.

As an alternative, have you thought about using the following plugin?:
https://forums.mybb-plugins.com/Thread-P...redits-2-0
Hey there, thanks for the reply.

Basically I'm using Button Maker from the CoinPayments Merchant Tools. It has some HTML POST variables that you can see here. It lists a "custom" variable and say's it's a "passthru" variable. I tried storing award id via input and fetched at the success page but it doesn't return anything. It's empty.


This is what I tried. In the awards page.

<input type="hidden" name="custom" value="{$award['aid']}">
In the success page
$award_id = $_POST['custom'];

It doesn't return anything. Or maybe I'm misunderstanding the word "passthru"? If you could help with this, it would be beneficial.


This is the complete button code that I'm using.
<form action="https://www.coinpayments.net/index.php" method="post"">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="cmd" value="_pay_simple">
<input type="hidden" name="reset" value="1">
<input type="hidden" name="merchant" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
<input type="hidden" name="item_name" value="Reward Icon">
<input type="hidden" name="item_desc" value="wadakela.xyz forum icon">
<input type="hidden" name="currency" value="USD">
<input type="hidden" name="amountf" value="xx.00000000">
<input type="hidden" name="want_shipping" value="0">
<input type="hidden" name="custom" value="{$award['aid']}">
<input type="hidden" name="success_url" value="https://wadakela.xyz/success.php">
<input type="hidden" name="cancel_url" value="https://wadakela.xyz/fail.php">
<input type="image" src="https://www.coinpayments.net/images/pub/buynow-wide-blue.png" alt="Buy Now with CoinPayments.net">
</form>

I hope it helps.


I also tried to get it done via sessions. But no luck. And yes, I haven't tested that plugin and it seems that it serves for a different purpose... I just want to get {$award['aid']} from the awards page to the success page via forms/button. Just need any possible method to do so...



It's sad to see no response.

I'm trying to propose some solutions if one can help in implementing it.

As you saw my above reply, the button actually uses a form to submit a request to CoinPayments. Is it possible to store $award['aid'] in the database table on submit? Would it help? Storing the value in the DB on submitting and fetching it out on the success page. - I tried but couldn't achieve it.

Also, above method shows, I'm trying to get it done with cookies. Is it possible to update a cookie upon form submission with $award['aid'] value? As the above method doesn't work. Any alternate? i.e calling a function to do so.

Can sessions help in this? I tried searching how can I create sessions in MyBB but didn't find anything. default PHP $_SESSION doesn't seem to be giving any output on success page. I tried.

Or otherwise, any possible solution you may have. would be appreciated.

Thank you.
To get the request data you need to use this code:
$request = file_get_contents('php://input');

Keep in mind that the page will be called many times each time the payments status change. So you need to also check the status of the payment.
Yeah, the "Simple Button Maker" tool offers a "Success URL" setting, but it doesn't looks like it will fulfill the same as a callback url from which you can get the necessary data.

I'd guess you will also need a new table to store results or something of that sort that allows you to store successful transactions.
Hey,

I'm thankful to all of you for putting your efforts in helping me. I'm glad to say that the issue is now resolved.

What was I doing wrong?
As stated above by @Omar G. , Simple Button Maker offer's a success URL but it is NOT a callback URL to IPN (Instant Payment Notification). Since the beginning, I thought CoinPayment is returning the POST values to success page.

Eventually at discord, @Chack1172 noticed that I need to setup an IPN URL and call the POSTed values there. Because before this, I was considering success URL to work same as IPN URL. As it was never mentioned by CoinPayments that the values are only returned in IPN.

So I setup a new IPN url configured it as per the IPN guide provided by CoinPayments and I'm able to fetch the values successfully in email/pm. Now it's easy for me to record the values in DB for future reference. Smile

Once again, thanks MyBB Team. Topic can be marked as sovled.