Lingering CartThrob Session - expressionengine

I'm running into a weird issue with CartThrob. Googling and CartThrob forums haven't revealed the answer.
After the cart is sent to the payment gateway, it will return to the template a "state" of either "authorized", "processing", "declined" or "failed".
What I'm finding is this "state" lingers around after browser refreshes, including full (no cache) browser refreshes.
This is mostly an issue with the "authorized" message. The "authorized" message appears when an order has been 100% completed.
What I'm seeing is if I start another order right away and go to the template where this code lives, the "authorized" message is still there. The message eventually goes away... maybe after 10/20 minutes or so. But it should go away immediately in my opinion, right? The order is done. Clear everything.
Is this "state" stored in the CartThrob session? Can I force clear the CartThrob session?
{exp:cartthrob:submitted_order_info}
{if authorized}
Order complete!
{if:elseif processing}
Your order is being processed!
{if:elseif declined}
Your credit card was declined: {error_message}
{if:elseif failed}
Your payment failed: {error_message}
{/if}
{/exp:cartthrob:submitted_order_info}

If you only want this info to show up on the post-checkout page the simplest option would be to add an order_status segment to your gateway return URL and then to only output the submitted_order_info tag if that segment is present.
I'm fairly sure that clear_cart just removes cart contents rather than flushing CT session data entirely (I think that's only ever triggered by logging out).

I sometimes find this helps clear cart, it works in similar way to {redirect="blah/blah"}
{exp:cartthrob:clear_cart return="about/stuff" }
And of course segment can help if need to trigger via a link
{if segment_3 == "foo"}
{exp:cartthrob:clear_cart return="about/stuff" }
{/if}

Related

NetSuite: Calling an API in real time as field values get updated

I'm looking for a way (using SuiteScript 2.0) to handle real-time persistent (stored) field updates, where a field might have changed in NetSuite (for example a lead time was just updated), and it doesn't matter if a user saved the change, or some other automated process changed that field. I just want to be able to pick up on that change:
The moment that it's done, and
Without regard for who or what kicked it off (e.g. it could be a person, but it could also be an automated change from a workflow, or a formula on the field itself which pulls values from another field)
Doing some research I found some options that looked somewhat promising at first. One being the afterSubmit event in a client script, and the other being the fieldChanged event. My issue however is, from what I understood those only really seem to be triggered by a user manually going in and making those changes, but this is only one part of the puzzle and doesn't seem to cover changes made outside of the scope of the user making those changes. Is that correct however? Or would one of those events still be able to capture changes done to that field regardless of who (or what) initiated or triggered the change, and right at the moment the change was saved/ persisted to the database?
UserEvents are basically triggers. In their deployment records you can set the context in which they fire so you can get them to fire in all circumstances (called contexts in Netsuite) but one.
That circumstance is User Events are not fired for record saves made in User Event scripts. i.e., if an AfterSubmit UserEvent script loads, changes and saves your record a fresh user event will not be fired.

Alexa skill have user confirm slot values

I'm building Alexa skills using Node.js in a lambda function and can't find any tutorials on the best way to confirm the data I have in the slots. I got to the point that all slots now have data but would like to have Alexa read back the request and get a confirmation from the user before proceeding. What's the best & proper way to do this?
At first I thought to use an emit with :elicitSlot but then I would need a new slot to do this and it looks very hackish.
for example:
if(all slots have a valid value){
this.emit(':elicitSlot','confirm',"You're request is .... with data .... is this correct?");
}
if(user confirmed data is valid){
// do something
}else{
// the data was not correct get the right data
}
For the whole intent confirmation, check here. For only slot confirmation, check here.
Also, for your followup question,
can the confirmation for the skill and slots be fine tuned for example if one of the slots is something like a name and alexa knows 100% what name I said can it skip the confirmation?
Short answer - of course you can if you do not maintain the dialog. However, it's strongly discouraged to rely on that.
In order to maintain a dialog, you have to monitor dialogState attribute of the intent request, and as long as it's not in state COMPLETED send response with attribute directives as [{'type': 'Dialog.Delegate'}] to keep it flowing. You can maintain finer control of the dialog - consult this doc. Moreover, you are strongly suggested to omit outputSpeech and reprompt in those responses, otherwise Alexa gets upset. Once dialog status is COMPLETED, you get confirmationStatus (for both Intent and slots) - SUCCESS(?)/DENIED/NONE. If the confirmation is not successful. I have seen multiple matches being sent as reply. However, when successful, only the matched slot value is returned.
P.S. I have had this weird issue. When Alexa is asking for confirmation for one slot value, if I deliberately decline twice in a row, it gives up and does nothing! Although, pretty much 99% of the time Alexa was spot on.
P.P.S. Turns out 2 attempts was a hard limitation from Alexa. This is supposed to be improved in next iterations.

Passing sever side zip/postcode to Stripe checkout

I am trying set up Stripe checkout so I can pass my server side customer zip/postcode to the Stripe checkout. It seems like it should be very simple but I cannot get it to work!
At it's simplest, the code I am using is:
<form action="charge.php" method="POST">
<script
src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="pk_test_redacted"
data-amount="2000"
data-name="Demo Site"
data-description="2 widgets (£20.00)"
data-currency="gbp"
data-address_zip="NG15 6UR">
</script>
</form>
the transaction works fine but it does not pass the zip/postcode so that it can be AVS checked.
What am I doing wrong?
Edit:
So apparently you cannot pass address information using checkout.js - you can only get the form to require the address from the customer when they put their card details in using
data-address="true2"
As far as I can tell, this means I can either hassle the customer by getting them to add their address details when I already have them!
or I have to use stripe.js which means I have build my own form, make it look pretty, validate it etc. Not a massive thing but, when there is a form there that does everything I need but accept address form fields passed at form creation, it is a little annoying :-(
If anyone knows otherwise I would love to hear it but this info came from the #stripe irc channel so I think it is probably correct.
As said in the Edit, I did have to use stripe.js and make my own form. Shame this small omission means quite a bit of extra work - but still much better than Paypal's mess of APIs and documentation! Cheaper too.
Untested but there may be a solution as you can update a card before the charge , you are able to update the customers card from the $token that you pass to your backend processor in php for example:
$cu = Stripe_Customer::retrieve($customer->id);
$card = $cu->cards->retrieve($token);
$card->address_city = $form['city'];
$card->address_line1 = $form['address_line_1'];
$card->address_line2 = $form['address_line_2'];
$card->address_state = $form['county'];
$card->address_country = "United Kingdom";
$card->address_zip = $form['postcode'];
Then take the charge
$charge = Stripe_Charge::create(array(
'customer' => $customer->id, etc...

Orchard CMS: Invoking two actions leads to duplicate notifications

Our Orchard application displays two of all notifications that are added to the notification service. So far we have traced the problem and know what is causing it, but are looking for a solution other than the obvious, for reasons I shall now elaborate.
So we are using a number of themes to render our Orchard based application. Within our layout, we have a Razor call to draw a header bar that displays a set of information about the user that is logged in.
#Html.Action("OutOfGameHeader", "Options", new { area = "Area.area.Location.Common" })
This action calls the OnResultExecuting() method in Orchard.UI.Notify.NotifyFilter which (among other things) populates the Messages Zone with the current set of notifications. When we make the call the render the Messages Zone, this same method runs again and the notifications are added to the Zone's shape again resulting in duplicate notification being displayed when the Zone is actually drawn.
Can anyone think of a solution that meets the following criteria:
Drawing the header without calling #Html.Action() to avoid OnResultExecuting() being triggered the first time.
Without creating a new Widget in a new Zone as this would involve us changing the manifest for dozens of existing themes to include it.
We also found this just below the point in the code where the notifications are added to the Zone, so if anyone knows anything more about it, that would be helpful too.
//todo: (heskew) probably need to keep duplicate messages from being pushed into the zone like the previous behavior
//baseViewModel.Messages = baseViewModel.Messages == null ? messageEntries .Messages.Union(messageEntries).ToList();
//baseViewModel.Zones.AddRenderPartial("content:before", "Messages", baseViewModel.Messages);
Any thoughts greatly appreciated.
Avoid Html.Action. This runs through the whole lifecycle as if this was a new request. That you think you need it is often a sign that you need to refactor and extract that logic that you want to re-use out of your controller. In Orchard, it's also better to use dynamic shapes.

Deleting a record in javascript

I need to delete some records related to the current record when it is deactivated. I can get the the event when the record is deactivated but I have looked around for some time on Google and this site for the code to delete records in javascript but I can't find any, though I know there must be some out there.
Can anyone help?
Thanks
I would be alright with doing this with a plugin, all I would need to know is how to pick up that the record has been deactivated
You can register a plugin on the SetState and SetStateDynamic messages (recommend the Pre event in your scenario). Each of these messages will pass an EntityMoniker in the InputParameters property bag which refers to the record that is being deactivated.
In your code you will need to:
Check that the new state in the SetState request is deactivated (since of course a record can usually be reactivated and you don't want to try deleting things then too, presumably)
Pick up the EntityMoniker from IPluginExecutionContext.InputParameters
Run your query to identify and delete related records
Exit the plugin to allow the SetState transaction to complete
If you really want to delete a record with JavaScript there is a sample on the MSDN.
Its a little long winded (its a CRUD example - create, retrieve, update & delete). But it should contain the information you need.
Note there is also an example on that page which doesnt use jQuery (if using jQuery is a problem).
That said I think for this operation would will find it easier to implement, test and maintain with a plugin (so I would go for Greg's answer).
Additionally a plugin will apply in all contexts, e.g. if you deactivate the record in a workflow your JavaScript will not run, but a plugin will.

Resources