How can I void a charge in the react-coinbase-commerce component? - coinbase-api

Whenever I successfully complete a charge from a particular checkout via the CoinbaseCommerceButton component the completion screen shows up when I go to buy a new item. How can I automatically have the screen begin anew when the charge is either successful, or the modal is closed?

The latest version allows you to pass in a prop called disableCaching that lets you create new charges every time a checkout is opened. But be aware:
Warning: If disableCaching is set to true, users that accidentally
close their payment windows will be unable to see their transaction's
status upon reopening.
Documented in the Readme: https://github.com/coinbase/react-coinbase-commerce

Related

REACT : pass a component to a function to that will implement component actions

We're trying to build a generic user permission handler for a system. We're currently using REACT to build the components. I do not write the codes myself, so please bear with the "pseudocode" below as my way of explaining the problem. (I'm asking this myself because my team's developers do not know how to implement this either.)
The idea is to have two functions, checkPermissions() and applyPermissions(), that will manage all component behaviours based on the user's permissions. This includes, but not limited to, the following:
Deciding whether to display or hide a component.
Enabling or disabling a component.
Allowing the user to proceed with the action he attempted to perform (e.g. deleting a record, adding a record, etc.).
Displaying the message that will tell the user why the action attempted was cancelled.
The checkPermissions() function does all the data gathering and processing of the user permissions. Once it has acquired the necessary data, it will decide what will be the component's action/response/state and prepares that response data to the applyPermissions() function, Then, the applyPermissions() function will perform the response. This means that the component itself will be passed to the checkPermissions() function (along with the user data) and then again to the applyPermissions() function (along with the response data) wherein the supposed response of the passed component will be implemented.
Now, our problem is whether this is possible at all with REACT -- to have a component be created/initialised inside one file and then have some of its specific behaviours and responses be handled on another file.
(Please see concept below.)
UIComponent tabMyContacts;
UIComponent tabMyMessages;
UIComponent tabMyRequests;
// some declarations of the UI component
// in this example, the following lines checks whether
// these 3 components will be visible/displayed
// based on the user's permissions
checkPermissions(tabMyContacts, appuserId);
checkPermissions(tabMyMessages, appuserId);
checkPermissions(tabMyRequests, appuserId);
------ separate file ------
function checkPermissions(component, appuserId){
//some process here to get the user permissions data
//some process to prepare the responses based on the acquired data
applyPermissions(component, componentResponse, componentResponseValue);
}
function applyPermissions(component, componentResponse, componentResponseValue) {
// componentResponseValue -- in this example, the possible values are TRUE or FALSE,
//but this variable can also contain the prompt message or some other info
if (componentResponse == "SET_VISIBLE"){
component.setVisible( componentResponseValue );
}
else if (componentResponse == "SET_ENABLED"){
component.setEnabled( componentResponseValue );
}
}
The idea is here is to not have the user permission handler be written repeatedly in every component that we add because we intend to implement a user permission system where the permissions (View, Edit, Add, Remove) are set to EVERY SINGLE component -- that is, the user permissions are set for down to each field, each button, etc. -- so you can imagine just how tedious it would be set the states per component and every single time a new one is added or modified.
I need to know if something like this is possible with REACT and there are alternative implementations that accomplishes the same goal.

Prompt when trying to dial a phone number using tel:// scheme on iOS 11

I am facing an issue, while trying to start a phone call from my iOS app using:
UIApplication open(_:options: completionHandler:)
iOS shows an confirmation popup/alert before starting the call with two button Call & Cancel and CompletionHandler called with a Bool parameter having true/false based on button action in iOS 10.
But now in iOS11 the problem is that the completionHandler is being called automatically before tapping on "Cancel" or "Call" button of confirmation popup, always having true value.
Is this a bug in iOS11 or is there something that I am doing wrong?
There has been a behavior change in when the closure is called in iOS 11. I cant say if this behavior will be reverted or if this is a bug.
But one of the ways you can identify when the user interacted with the popup is by adding a notification listener around UIApplicationDidBecomeActive in the completion closure of openURL(). To identify whether the call was clicked or not you will need to create another custom notification and listener on the CTCallCenter. That was the best way through which I was able to identify it, there might be better solutions though :D
completionHandler will get a call if your given URL gets open success or failure, this has nothing to do with Cancel & Call buttons on Alert
see what Apple docs has to say about it HERE
completionHandler
The block to execute with the results. Provide a
value for this parameter if you want to be informed of the success or
failure of opening the URL. This block is executed asynchronously on
your app's main thread. The block has no return value and takes the
following parameter:
success
A Boolean indicating whether the URL was
opened successfully.

Angular seems to fire on its own

I have a $http.put function that updates my database, this happens on a button click. After I update the database once, and stay on the page, with no interaction at all the update function gets called and will update the database with the last information that was inputted.
I've triple checked my code, there is only one occurrence of my update function being called. And the $http.put is inside $scope.update that is an anonymous function that calls the $http.put.
If I update information and then leave the page, and then come back the function does not fire on it's own.
Here is my Github for the project. I will pull out any specific code that you want to see, but I'm not sure what to show because there are 4 files involved. Those files are
(client/scripts/app.js)
(routes/products.js)
(public/views/routes/adminIndex.html)
(public/views/routes/modProduct.html)
Code is Here
Add a console.trace() just before the $http call to see what is calling it.
You can also use the developper console of your browser and add a breakpoint that will stop the code execution and let you inspect everything (stack trace, current context, etc). Chrome is particularly good at that.

Lock a record from other users when editing by single user in CakePHP 2.4

I am implementing a CakePHP 2.4 app.
I have User and Article as Models.
I have no articles/view action; only articles/edit and articles/delete actions.
When any User accesses the articles/edit webpage regardless as a GET or POST, that particular Article is locked from editing/deleting by other Users.
The following is the crucial part I need advice on.
If a User stays on articles/edit/23 but there is no activity for 30 minutes,
-- OR --
When the User leaves articles/edit/23 page,
then the articles/23 is now available for edit/delete by other Users.
Off the top of my mind, i know that in articles table, i need a field called currently_locked_by field that holds the user_id of the User currently in control.
My problem is with detecting the session inactivity and knowing that the User has left the edit page.
I am defining session inactivity in the edit page as when the User does not type anything in any input elements or changes any dropdown selection or checks/uncheck any checkbox.
Suggestions?
You could create a lock table with a combination of the user, resource and lock time. (Regarding your spec's when to start the inactivity - I recommend going simpler to start: "when they person loads the page". Otherwise you are also writing javascript to write to your database at the end of every field change.)
Whenever a person goes to the edit page,
They check that table for the resource and lock time. If the record does not exist or the lock time has been exceeded it is safe for them to edit.
If they can edit, then they insert a record as needed (and delete any records with that resource.)
This should take care of the timeout requirement as long you make sure the person still has a lock (or another hasn't locked the record) when they try to save their changes.
One technique to handle the leaving of pages, is to put in a beforeFilter test that removes all locks for that person. The downsides
You still can't tell if the person leaves and goes to some external
site.
The beforeFilter does add overhead to every page view.
If your users run two or more tabs, then navigating other tabs will
release the lock.
You could also just have every outbound link on that page release the lock (like going to an interstitial page) and let any departures via closing the tab, using address bar, etc timeout. (It depends on how your users work.)

Providing notifications to the current user from an Apex trigger in Salesforce

I'm trying to figure out a user friendly way to pass messages to users from my Apex code. I have a trigger which fires after insert/update of a lead, which then filters the list of updates and triggers a #future method which pushes the lead data out to an external web service and updates the converted account with some of the returned values.
I'd like to do the following (where X, Y and Z are any number of leads from 1 to 50)
notify the user converting the leads that leads X, Y and Z will be exported (I'll know this during the trigger execution).
notify the user whether the export succeeded or failed (which will be known for each of X, Y and Z when the #future method runs).
What is the recommended way to pass this information back to the user? I'd prefer not to use email (as this would trigger one email per record, which is pretty spammy and unpleasant). Is there another way to inject notification messages into a page? I've tried ApexPages.addMessage() but it doesn't seem to do anything for me (no error, but no notice either).
addMessage() works with both Visualforce pages and standard pages when there's a current page active, so using this in the trigger should work fine if the user is firing the action from a button / VF page. Using this won't work from your #future method however because it runs asynchronously in the background.
Maybe the best solution would be to use a custom message object, which has a list of fields modified, when, and has a lookup to the appropriate user (or uses them as the owner). You could then create a simple VF page and controller which when viewed queries for records in that object related to the current user and provides an option to delete them (you could automatically delete them after pulling them from the DB but you run the risk of the user not actually noticing a message). You can then take this page and use it as part of a dashboard component, so anytime the user is viewing their Home page they could see a list of notifications.
Finally another option might be making use of Chatter, pumping the messages to the user via that which will then also show up in digest emails etc..

Resources