Run code once for new visitors with laravel - javascript

I am using laravel 8 and I am creating a world wide webshop.
There are 2 currencies available: usd & euro.
But how can i run code only once when a new visitor comes to my website?
What i want to do is check if someone lives in europe and set the currency to euro, otherwise set it to usd.
But this code should only run once per visitor because they can change the currency and it should not automatically transfer back to the original currency.

I'd get their IP address from the Request object, either by DI-ing in the controller method, or the helper, request()->ip(). Run the IP through a geolocation API, and log it in your database.
Might want to trigger this off creating an account though, or else have some garbage collection of older records, or else that visitor_location log could get a little cumbersome.

Related

How to prevent shopping cart alterations in another tab when paymentintent is already created

Has anyone figured out a solution to this? I seem to have gotten to the same conclusion with no solution.
If I were to go the my app's checkout page, the payintent is created in the backend (explained the process below). So no after the payIntent is created, if i open a new tab and go the menu and add a new menu item, firestore will show the new (correct) total, but since the payment intent is created stripe charges the old (wrong) total.
What I am doing is
Every time the page loads, I send a GET request to my backend which verifies the identity of the user (using firestore/firebase).
Checks if there is a payment intent (payement intents are stored in firestore corresponding to the user)
A. if payintent does not exist under user create one
B. if payintent does exist retrieve payintent from stripe and check if it has .status===succeeded. IF it has succeeded create a new one and if it has not succeeded update the old one. The amount for all payIntents is calculated using total in firestore
(and ofc if the users cart is empty a payintent is not created)
Send back to the frontend the payInent.clienSecret and cart items to populate page
From the front end using stripe elements and confirmPayment confirm the payment
(using ngrok the page loads in about 800-1200ms so not too bad i think)
Possible solutions are using webhooks, when payintent is processing check and update the pricing but that seems like duct taped solution (if it were to even work). OR using webhooks when payment has succeeded update the payment, again seems like a duct tape solution (if it were to even work).
EDIT: possible solution 3 cofirmPayment in the backend but according to documentation that takes away 3ds authentication which is the reason I am doing confirmPayment in the front end anyways
SOLUTION: The missing piece is that you need to update the Payment Intent's amount when something is added to their cart. Once you add that I think that will solve your issue.
So a function to create payment intent and update payment intent (when there is already a payment intent created) on add to cart. And then a final update paymentIntent on the checkout page whenever they delete an item or if they edit the item
Thank you Justin Michael
I'm not sure I completely understand your question. If you confirm a Payment Intent client-side using its client secret the Payment Intent will attempt to charge whatever the current amount set on it is. Stripe will never use a previous or "old" amount.
As far as a solution, I recommend you retrieve the Payment Intent client-side using Stripe.js when your customer clicks on your "pay" button and see if the currently-set amount on the Payment Intent matches what you're currently displaying to them. If it doesn't match abort the payment process, update your state client-side based on the latest version of the Payment Intent you just retrieved, prompt the customer to confirm the new amount, and ask them to click on "pay" again.

Smart Contracts: Dynamically make and fill variables in Javascript by taking informations from HTML to send in MetaMask

As you can see, i am working on smart contracts.
I have a parsing function that when i give an ABI/JSON it is showing up the function with is variable.
Now, i want the informations that getting out from the parsing to sending them to the MetaMask, but i don't know how is proper to get them and i need help with the source code.
I want to have in one variable the function type as it is shown at the picture with the arrow.
And i want making variables name with the names that are shown (_startTime as an example) with the value from the input box that the user will give.
Metamask is a plugin used to execute the transaction. You can also send data with the transaction to the Metamask. To initiate the transaction first you have to login into the Metamask. Later you have to select the Network in the metamask and use Web3 wrapper to execute the transaction. I did that using Truffle and running local blockchain on my PC.

j3k0 cordova plugin purchase android transaction receipt is not updated

I am trying to set up j3k0 Plugin Purchase for subscriptions on Android and somewhat have it working.
I register my products and then call store.refresh()
On my products page I call store.get('my_id') and retrieve the products which I display
On purchase I call store.order('my_id') which does initiate the billing popup. I confirm and the first time everything appears fine
I have store.when('my_id').approved(function(data) { my code in here }); which does get called and worked the first time. Now every time I try to test it I get the same data.transaction back so I keep referencing the original receipt data which is cancelled when I try to validate on my server.
store.when('my_id').approved(function(data) {
var receiptIsAlwaysTheSame = data.transaction.receipt;
//I send the receipt to my server here to validate
});
I do get valid test emails from the store every time I subscribe or cancel so not quite sure why the transaction seems to be cached. I did see this older issue with iOS on the GitHub site which just recently went on the backlog and not sure if it is similar or what: Receipt Validation
UPDATE
So after 3 days I made another purchase and the method gave me back a new valid receipt with new transaction data. My first thought was the grace period on my product, but that is set to 0 days anyway. So still not sure why I have to wait 3 days before making another purchase. If anybody knows how to force this to refresh before then that would be great.
I'm trying to implement my own server for validating non-renewing subscriptions, in order that these can be restored on new app install etc. I'd like to be able to do it without collecting a unique ID from the user e.g. email address. Is that possible?

How to perform server validations based on query results with Firebase?

When inserting a record I need to be able to run one or more queries on the server which will reject the insert if it finds any results. Will Firebase allow me to do this? It can't be specified on the client or it could be easily subverted.
For a more concrete example, I have a Meteor app that currently let's me do rate limiting on votes with some pretty simple code. I would like to implement this in Firebase. (Please forgive the CoffeeScript)
#VoteFrequency =
votesPer: (sinceDelta, sinceUnit) ->
Votes.find(
pollId: #pollId
ip: #ip
createdAt:
$gte: moment().add(-sinceDelta, sinceUnit).toDate()
).count()
withinLimits: (ip, pollId) ->
#ip = ip
#pollId = pollId
# Allow x votes per y seconds
#votesPer(10, 'seconds') < 1 &&
#votesPer(1, 'hours') < 15 &&
#votesPer(1, 'days') < 150
As you can see, it queries the database for previous votes matching the IP address and more recent than a timestamp (calculated using a delta from current time - interval). If it finds any results for any of these limits, it returns false, which tells the caller not to insert the new vote.
To be clear, I'm not looking for a solution where I add my own server into the mix. Once I have to do that, FireBase loses much of its appeal to me at least.
From what I can tell so far, this doesn't appear to be something I can implement just with a browser / native client and firebase alone.
You cannot run your own code on Firebase's servers. So trying to map an existing three-tier solution to Firebase will require more than evaluating how to port each script.
As far as I can see you with these main options:
you implement the same logic in Firebase's security rules
you run this code on a server of your own that acts as a middle tier between your clients and Firebase
you run this code on a server of your own, that acts as a "bot" to a Firebase database.
I'll assume #1 is clear, though certainly not trivial. For example: Firebase's security rules don't have access to the IP address of the client, so you'll have to find a way to (securely) insert that into the data. Also: rate-limiting is possible in Firebase security rules, but not easy.
#2 is probably also clear. But it would keep you on your current three-tier architecture with custom middle-ware. You'd just be replacing your current data store with Firebase. If that's what you're looking for, this is definitely the simplest migration approach.
#3 is described in pattern 2 of this blog post. In this case you could consider letting the clients write their vote and IP address to a "staging" node. The bot-script then reads them from the staging area, validates that they are within the rules and writes to the official node (where regular clients don't have access).

Pubnub presence limit to 20

I'm implementing presence with pubnub, and I'm encountering a problem, I create a method to get the presence in python, and its working properly, when I connect one to 20 users simultaniously, but once I created more, I didn't get the proper response of the joins users.. I created a simple js script to subscribe users..
var pubnub =[];
for(i=0; i<=100;i++) {
pubnub[i] = PUBNUB.init({
subscribe_key: "subkey",
uuid: "user"+i
});
}
After the first 20 I just get the occupancy in the response of the presence method, instead of the usual, join or leave action with the corresponding uuid.
Does it have a limitation, or perhaps, pubnub know that I'm opening them from the same ip and its blocking subscriptions somehow? I would like to know how it is the behaviour.
#cri_sys, this is a server-side optimization to be sure we don't flood you with data when there is too much presence data coming over the line.
Contact us at support#pubnub.com, and we can adjust it to < 20 behavior for you, or go into more detail on why you may want the alternative behavior when > 20.
geremy
The Presence Announce Max property is now exposed as a property in the Presence add-on panel in your account portal. You can set the value as high as 100. If you want it set higher, you need to contact support#pubnub.com.

Categories