Implementing gift card - asp.net

I'm meeting an issue to implement gift card in an e-commerce website working with paypal.
I'll try to be as clear as possible.
Once the user has validate his cart, he can enter a code as gift card to get a discount. The gift card (and the code) can be used only once and it isnt linked to the user.
So when the user enter the code, I check if it exist if it allready has been used, get the discount and so on...
On the postsale of paypal (once the paiment has been accepted), I set the gift card as used.
Now, how can I prevent the gift card beeing used twice (or more). Because when user enter the code and goes to paypal, another user can use this same gift card while the first user did'nt confirm the paiment (and didnt process the postsale).
I thought giving a status to the gift card, for instance 'In use' before redirecting to paypal but if the user leave paypal without confirming his purchase, the gift card will always be InUse and then I wouldnt be able to check it again....
I hope I've been understood and thanx for your help :)

Well, you could check if the code has been used when they enter it, then check again at the point of the transaction being completed. The second check would have to be implemented carefully, with a single locking database transaction that checks if the code has been used, then marks it as being used.
If the code had been used by someone else before the transaction is completed, the transaction would have to fail with an error. However, presumably this would be quite a rare case.
Beyond this, I wonder if you should rethink your design. A single-use code that is not linked to a user seems unusual--normally this would be linked to a specific user, which would make it easier to handle. What is your use case?

Related

Woocommerce shipping modifications required to support HTTP API shipping calcs

Woocommerce shipping calculations running too often.
Woocommerce shipping setup works great until you build a custom shipping plugin that uses external quoting systems via HTTP API calls, at which point you realize that the shipping is calculated dozens of times unnecessarily during the order process - slowing everything down.
We make API calls to external servers at our Australian Postal System and also a courier aggregator system to get post and shipping rates. This takes about 5 seconds to complete the two API calls and since the calculate_shipping() function seems to be called on every cart addition & modification, on entry to the checkout page and then on every single keystroke for relevant address fields in the checkout page there are 5-second delays and unnecessary HTTP calls everywhere.
The ajax calls from every keystroke on the checkout page also seem to be queued up and process one after the other so the user can sit watching for 30 seconds while the shipping options are populated then cleared several times before being able to choose one.
Another silly consequence is that the errors that come back from the quoting of an incomplete address end up scrolling the screen up to the top where the notices are being displayed which stops the user from completing typing the address.
So the question is How to stop WC from calling calculate_shipping() until all shipping fields have been completed and maybe the last field has lost focus - or any alternative suggestions to do similar and avoid the multiple calls.
In order to remove the shipping calculations on every cart addition, I have simply tested for the current request URI and return straight out if it is not
if ('https://aaa.bbb/checkout/' !== $_SERVER['HTTP_REFERER']) {
return;
}
Seems to be ok, however, I expect there are some complications later as otherwise why would WC be doing this on every cart addition.
On the checkout, though it's a different story.
I need the shipping to run, but not on every new character typed into an address field as seems to be the default functionality.
There seems to be a timer in play and if you take more than a seconds pause during typing your address it fires update_checkout() or similar which calls calculate_shipping() and I so end up contacting the post servers and couriers servers to ask for a new quote. (they will tire of this DOS attack I'm sure)
I've been looking into the checkout.js script but don't really want to mess with WC functionality and not be able to update so not sure if I want to change this.
None relevant at this stage
What I would like is for shipping not to be calculated until all items are in the cart and the user has finished typing in their address - anything else seems a bit silly.

Google Analytics Ecommerce / Difference between 'ec:addItem', 'ec:addTransaction' and 'ec:send'

I would look for some feedback on tracking user activity on an commerce website using th google analytics commerce capabilities.
I can't fully understand those 3 parts :
Adding an item (ecommerce:addItem) : obviously when some user add a thing to the cart
Adding a Transaction (ecommerce:addTransaction) : that's where I'm very confused
Sending the data (ecommerce:send) : that's obvious
Can those 3 event append at a different moment ? in what manner ?
What would be a real-world use case that would make you use execute ecommerce:addTransaction and ecommerce:send at a different moment ?
This thing makes me wonder a lot, and I'd like to have some experienced feedback on this as you tend to easily break your stats if something is not done week enough
Thanks in advance
EDIT
So the main purpose right here is to get stats for the pending orders (you add stuff to your cart), and the complete orders (you paid for the things you added).
Right now I only send it all when the order is complete, and things are working pretty good in analytics, but I just don't know anything about the ones that did not complete.
This question was a lack of knowledge.
Simple ecommerce plugin has nothing to do with the enhanced ecommerce plugin
You won't track that much with the first one, except the checkouts. A plain, one order at a time, revenue value.
If you want a deep insight on your users behaviors (when i say deep, I mean it), You have to go for the second one.
We might be able to debate over the unusefullness of the first one; and the fact that its existence in itself compared to the second is completely misleading, as when you first get in, as usual with google, you get flooded by an endless documentation
ecommerce:addItem does not add items to a cart; it adds items to a transaction (with "conventional" ecommcerce tracking there is no cart tracking, you'd have to use enhanced ecommerce tracking. Actually your title refers to enhanced ("ec:") and your question to conventional ecommerce ("ecommerce:") tracking).
So ecommerce:addTransaction starts a transaction; here goes the stuff that affects the transaction as a whole, like transaction id, tax on the total purchase or shipping costs.
Now that you have started the transaction you can add items to it that are associated via the transaction id.
Finally the ecommerce:send command tells Universal Analytics that the transaction should be processed on the server. "send" is actuall a misnomer; addItem and addTransaction do already send data to the server (they each create an request to the tracking server and thus count towards your hit quota).
The reason for this is, as far as I can tell, that the information is transmitted via url parameters (you call the Google Analytics endpoint which returns an transparent pixel). The maximum length for an url request is limited (actual limits depend on browser and browser version).
So the transaction is broken up into multiple parts not because you want to execute the commands at different moments but so it can be transmitted via Url parameters without being truncated. The send command merely tells that you are now finished adding new parts to the transaction and the data can now be processed.

Need some hints for my own WP Theme

After taking some online tutorials I am willing to create my own custom theme for my myself. This is going to be an online Contact Lense store! So far I have learned how to generate and use Custom Post Types, Custom Taxonamyies, Metaboxes , and Option pages.but there is still one confusing part left for me(hopefully not more! :-))
I need to get some user inputs through HTML Select Options like following image to finalize the users orders:
Now my question is:
1- Do I have to create some thing lik Metaboxes to manipulate these data from users?
2- can I handle these kind of data through simple Form ans Post function in PHP? If so where should I store these data? Do I have to create a table on my own to handle these things?
I really appreciate your time regrading this post,
What you're asking for carries a little more complexity than you think!
Let's break this down into its meaningful steps:
A user visits your shop, and decides that they like what they see and wants to make an order
The user fills out a form defining their exact eye requirements, quantity, as well as their contact information
Upon completing this form, a new order has been created
But wait.... how will you get paid? What happens if the user's computer explodes before the payment goes through? How will you know to send them their contacts without first knowing the payment even succeeded?
This is where things start to get tricky. You need to be able to keep a record of orders for the sake of your users, but you also need to look out for your own interests too. Your business is doomed to fail if you're sending out expensive products to people without the proper assurance that you're getting paid.
This is where you'll need to set up a Merchant Account with a service like PayPal or Google Checkout. As much as I despise PayPal, their Instant Payment Notification (IPN) System has been very reliable for me. What this does is automatically send a POST request to your server with all of the information you need to finalize the checkout process and alert your user that their payment has either succeeded or failed.
So with this in mind, how does this affect our step-by-step process?
A user visits your shop, and decides that they like what they see and wants to make an order
The user fills out a form defining their exact eye requirements, quantity, as well as their contact information
Upon completing this form, a new order has been created with a status of pending
The user is then sent to PayPal/Google Checkout to enter their Credit Card information to complete their purchase
PayPal/Google processes the payment
PayPal/Google sends your server the results of the processed payment
The corresponding order is updated with a status of Payment Received or Payment Failed for your own records
You send out the product to a very satisfied customer
So what will this mean from a Wordpress standpoint?
My first suggestion:
Check if a Plugin already exists that can handle this for you!!!
Seriously, this will make your life much easier. Handling people's money as well as your own stock is a nightmare all in itself, you don't want to be responsible for handling the code that drives it, or the possibility of security holes that you might not know about (that other plugins may have already addressed). WooCommerce is a popular one. See if that can handle what you need.
If a Plugin can't do it for you, then you'll need to:
Register a Custom Post Type for Orders
Create a new Order Post using wp_insert_post when a user submits the form with their POST data
Save the relevant POST data you need as metadata using update_post_meta
Send PayPal/Google/Whatever some Custom Information it needs to hang on to - in this case, the newly created Order Post ID - so that it can send it back to your own server
Set up a side-script to process the data sent by PayPal/Google Checkout/Whatever and send an email to the user detailing the status of their purchase and update the corresponding Order Post ID that was sent back by PayPal/Google Checkout/Whatever
(Optional) Set up a CRON Job to periodically scan all Pending orders in case a user's session was interrupted, or they bailed at the last second during checkout and send them an email notifying them about this and provide them a link to your website to reopen, reevaluate, and resend the order, or cancel and clear it from your database
Quite honestly, this would take even a seasoned Developer at least a few weeks worth of work just to get it in working condition. Presentation is a whole different animal.
Hopefully this will give you a step in the right direction. I doubt anybody here will give you the code to do what you need, because there's just too much to post. Entire libraries are built just for these kinds of things.
Good luck!

Recurring billing variable amount without storing credit card information

I have implemented few payment websites using PayPal Standard, PayPal Website Pro, PayPal Express and Authorize.Net.
Now I'm implementing a website which requires recurring billing. My only problem is variable amount, since I do not store credit card information, and amount is not fixed in each cycle.
Can we use either PayPal or Authorize.Net for my project? If not, could you please recommend any reliable payment gateway ($US for payment, and gateway located in US please) for that matter?
You can use a service like Authorize.Net's Customer Information Manager (CIM) to store the credit card and billing information for you and then you create your own scheduling engine that charges against the payment method you have stored for them using CIM. CIM also allows you to make off-cycle payments at any time as well.
Well the variable amount to bill shouldn't be a problem if you can put together whatever formula would be used in code. However if you aren't storing the actual credit card info (and I can understand why), then I don't see how you'd be able to charge the customer every month. Normally you need a credit card or bank information to do a direct transfer.
If you absolutely cannot store the information, then the only thing I can imagine is putting together an automated calculation and notification system that can send the customer an email with a link that brings them to a form so they can enter the information as simply as possible. Otherwise you'll need to save their credit card info somewhere secure and simply bill them every month, which isn't uncommon.
Have you looked into PayPal's IPN variables?
https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside
Typically you have to cancel then reapprove a new subscription... but perhaps you can use the variables some how to do that programmatically.
I found a solution. PayPal calls ProcessReferencePayment.
At first, I need to charge the credit card using DoDirectPayment, and store the successful transaction number.
After that, I just call DoReferenceTransaction along with OrderTotal and ReferenceID (the previous transaction number).
DoReferenceTransactionRequestDetailsType
DoReferenceTransactionReq

IPN's/Ubercart and everything that comes with them: I want to make sure I have the money

Sorry if the title's a bit vaque, I promise I'll clear it up bellow:
First of all, a while ago I asked a question about selling serial keys :
How can I execute a custom script after purchase with Ubercart for Drupal
The information I posted there may help clear things up in this question but I doubt it much because this question is a bit more general.
Basically, I don't want to execute my custom code until I know the payment has been cleared and the moneys in my account. I was a bit unsure what the conditional action thats trigger is 'Customer completes check out' did though? When it says they completed checkout does it necessarily mean successfully and the money is in my account or not?
If not, how do I make Ubercart wait until it knows I've got the money from any PSP (e.g. Google Checkout, PayPal, etc) to execute my custom code? I can't work it out, is it even possible?
It's not documented or exposed as something that should be reliable but I think that using the 'Customer completes check out' trigger is the way to go.
Bear in mind that the following applies to Ubercart 6.x-2.4. (Latest version as of today)
From what I looked at the code, it seems that the trigger is only executed on successful orders. Whether a successful order means that you have received payment, that depends a lot on your current configuration and the different payment gateways or method you are using, but in general situations and configuration.
That trigger is only launched from one function:
function uc_cart_complete_sale($order, $login = FALSE);
If you do a module-wide search on when that function is executed, it should give you a rough idea on the different situations. Basically I found out that it's being executed from a few payment modules (paypal and 2checkout for example) as well as when you reach the cart/checkout/complete drupal page, which is generally on successful orders. The paypal module, which you specifically asked, seems to be calling that function when a 'Completed' IPN status is received.
It shouldn't be hard to try out a few purchases (right and wrong) and see if your trigger executes only when the order is properly charged.

Resources