Customizing "PayPal" button for PayPal Marketplace (API) - paypal

I am developing my app with PayPal Marketplace API for the first time.
Among other steps, I need to customize a "PayPal checkout" button. I did this by following instructions on this page.
In function "payment" (see the original code segment below), I supposed to provide a call-back url for CREATE_URL:
// payment() is called when the button is clicked
payment: function() {
// Set up a url on your server to create the payment
var CREATE_URL = '/demo/checkout/api/paypal/order/create/';
// Make a call to your server to set up the payment
return paypal.request.post(CREATE_URL)
.then(function(res) {
return res.id;
});
}
By reading this, I am puzzled why the CREATE_URL value is not a fullpath url starting with "http" or "https"? I have the similar question for EXECUTE_URL in an ensuing segment of the html file.
What type of RequestBody should my REST controller expect?
What action should my app take at the url for "CREATE_URL"? My intuition is to call the Order API to create an order (among other things in my database). Is this correct?

I can address your questions one at a time:
By reading this, I am puzzled why the CREATE_URL value is not a fullpath url starting with "http" or "https"? I have the similar question for EXECUTE_URL in an ensuing segment of the html file.
You don't have to have a full path URL (known as absolute path) because the path that you provide for CREATE_URL is on your own server. So the code where you have your button is on a page like exampleButton.html and when you click the button, it takes you to a script, such as
var CREATE_URL = '/demo/checkout/api/paypal/order/create/';
which is an index page which will run the Create Order API method with the data that you pass. Here is another example implementing a payment button with checkout.js using a server side language.
What type of RequestBody should my REST controller expect?
Your request body will receive the payment data from the JavaScript data parameter, which should be JSON format. You then pass this to the server side when you receive the POST data.
An even simpler implementation is to use the client-side integration to create the order.
What action should my app take at the url for "CREATE_URL"? My intuition is to call the Order API to create an order (among other things in my database). Is this correct?
Your app should automatically run the create order method. This script works with JavaScript promises, so will wait for a response, like getting a successful authorization (or failure) from the customer before attempting to execute the payment.

Related

Redirect URL using Firebase Dynamic / Deep Links is losing query parameters

In my Flutter (Android/iOS) app I am using Firebase Dynamic Links for Patreon.com OAuth2 apis.
My dynamic link is https://myappname.page.link/patreon
The deep link is https://myappname.net/patreon
Patreon is using the https://myappname.page.link/patreon as a redirect_url , and is supposed to append some parameters to it, so it looks like
https://myappname.net/patreon?code=xxx
However, all I receive inside my app is the naked url https://myappname.net/patreon
There are no parameters attached to it.
So how can I tell Firebase to preserve the query parameters Patreon is attaching to the redirect_url?
As an alternate question, is there a better way to listen for incoming response inside of a Flutter app, without the use of Dynamic Links?
You loose all parameters by using that.
If you're relying on Patreon to send back that parameter I'd suggest to generate a small proxy where you can redirect your calls to the dynamic link by generating it on the fly.
So:
Patreon shares www.myhost.com/supah-link?p1=aaa&p2=bbb
Your micro-service which runs on www.myhost.com/supah-link receives the call
You generate a dynamic link like the following:
https://example.page.link/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ibi=com.example.ios&isi=1234567&ius=exampleapp&p1=aaa&p2=bbb
NOTE: Pay attention to the &p1=aaa&p2=bbb parameters added
Return a 302 and redirect to your newly generated link
Based on how you configure it from the console this link can redirect to the store or your app, in your app you can listen for the link as follows:
FirebaseDynamicLinks.instance.onLink(
onSuccess: (dynamicLink) async => handleDeepLink(dynamicLink?.link),
);
In handleDeepLink you can parse your custom query parameters.
NOTE: The URL parameter you pass via the dynamic link HAS TO BE ENCODED! Which means your link will look more like this:
https://example.page.link/?link=https%3A%2F%2Fwww.example.com%2Fsomeresource%26apn%3Dcom.example.android%26amv%3D3%26ibi%3Dcom.example.ios%26isi%3D1234567%26ius%3Dexampleapp%26p1%3Daaa%26p2%3Dbbb

How to get url of a tab before the page gets loaded in Mozilla Addon SDK?

I am creating an addon for blocking sites on user request.I have done- getting user input and storing in simple-storage.Now i want to access the url of the tab(s) before the page gets loaded so that i can process the url and gets it hostname to block the site.
You do this using the PageMod module with onAttach.
pageMod.PageMod({
contentScriptWhen: 'start', //This says not to wait until the page is ready
include: ['*'],
//Forget about contentScript(File), we're not attaching a script
onAttach: function(worker) {
var tabUrl = worker.tab.url;
if(tabUrl==myString) worker.tab.url = 'http://arabcrunch.com/wp-content/uploads/2013/05/block-website.jpeg'
}
});
But I recommend doing it differently. Instead of checking every URL yourself then doing something , you create an array of URLs or partial URLs and set include: myArrayOfUrls. Then you don't need the if clause in onAttach, you already know that it's one of the websites you want to block.
You can register to the http-on-modify-request notification from the Observer Service. You'll get notified just before the request is made and you can get the URL.
See the following resources on the topic:
Setting HTTP request headers for registration example and Observer Notifications for the list of notifications you can register to.
What you describe is essentially what the Adblock Plus extension is doing, maybe you could use it directly or look into its code.

Simplest example for sending post data via links in Zend Framework

Starting with Zend and I´d like to know what is the simplest way of sending POST data to another page, not by forms, but by some link in my view instead. Thanks :)
You can't send POST data through a link. At least not through a normal link. Link can only carry GET data.
If you need to send POST over a link it's most certainly a design flaw.
If you're 100% sure, that you need it, you can do that using jQuery and onclick event. It`s not possible to do it without javascript. Other option would be to send it using form with hidden fields with single submit button visible - that would even work without javascript.
Normal hyperlinks in HTML are sent with GET requests and are not supposed to change the state of the resource being accessed. This is known as being idempotent. You can repeat the request over and over, and the result of each succeeding request to the same URL is the same as the first one.
POST requests don't have this restriction and are intended for when the user needs to change something (such as creating a new resource.)
It's not possible to send a POST request via a normal HTML link. And even if you find a way, it breaks an almost universal expectation that web users have. What are you trying to accomplish? Maybe there's a better way.
But to answer your question, you could use something like jQuery to capture the "click" event and make it do a POST request:
$('.my-link').click(function() {
var url = $(this).attr('href');
var data = {};
$.post(url, data, function() {
window.alert('success!');
});
return false;
});
If your URL has any query parameters, i.e. "?foo=bar&baz=bum", then you'd probably need to strip them off of the URL and pass them as a second parameter to the $.post() function. This is left as an exercise for the reader. ;-)

Why GWT URL doesn't change on an event or a service call?

I have two questions:
Q: 1
I'm currently developing a GWT app. The entry point for the app is: ImageViewer.java. I could well access it by http://127.0.0.1:8888/ImageViewer.html?gwt.codesvr=127.0.0.1:9997. I have a service called "Search" which has corresponding "Async" and "Impl"'s defined. Now, I call the service from client side, using RPC. I could call the service, obtain return value. Everything works fine.
However, I expect the application to show a behavioral change on URL. i.e. when a service is being accessed, I thought it would be reflected on the browser's URL something like: http://127.0.0.1:8888/search?gwt.codesvr=127.0.0.1:9997 as I've modified web.xml. However, this behavior is not realized. Any particular reason why this is not reflected??
Q:2
This one is a reverse of the previous ques. i.e. I have an application running. Let's say it has an entrypoint class(Imageviewer.java) and another composite class (searchClass.java) which would be loaded on the Imageviewer based on an event. This searchClass invokes the "search" service mentioned in the previous question.
I could load the "searchClass" in "Imageviewer", invoke the service, and the service also returns the value needed. Everything works fine... But,
I need something like this: by just typing this query string:
http://127.0.0.1:8888/search?value=John
I want the "searchClass" to be loaded on the "ImageViewer", call the service using the value(which is "john" in this case) and display the result. Is this possible at all?
what I've tried: I have tried to create a httpServletClass on the server and mapped it with the URL and could do the search. The search returns appropriate results. However, I want the results from the server to be displayed on the client. Remember, I'm directly using a servlet to read the URL and so there is no value being passed from client to server.
Thanks in advance.
A: 1. To change URL, the hash part, you need to set new history token in the History class. More about history management in this article.
A: 2. For the second part you could achieve it by changing the history token, for instance "http://127.0.0.1/search#value=John". The history service will trigger an event if the # part changes. You could also use the part with "?", as in your example, if you use Window.Location , but it will cause reload of the application, which would put the whole idea of using GWT in question.
RPC (AJAX) calls are done Via XHR and do not change the browser URL.
You can't (with the URL you presented). GWT apps normally run in one web page, i.e. the URL does not change (see how gmail changes browser url bar). What you can do is enable GWT history support. Then your url would be http://host/#search?value=queryu

MVC 2.0 Post Form to action instead of redirect to action

I am using T4MVC to redirect to another action return RedirectToAction(MVC.MyController.MyAction());.
In result it is doing get request.
Is there any way to make post request from controller. I want to keep all the same but only make post instead get. I cant find any methods for that. I found one post helper here http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx but i cant pass any values i need using this post helper. I was trying to pass values through TempData but they are not coming when i using this helper. May be some one have any ideas?
The reason i want to do this because when user come from one controller to another and then if user click update or just click enter in browser address bar, page will break.
Should i use session for that reason?
A RedirectToAction will always perform a GET, never a POST (it returns a HTTP 302 to the browser, which will then issue a GET request).
To persist data across the redirect, if it is data that can be easily represented as a string and stored in the query string, then you can just add it to the route values of the redirect.
e.g.
return RedirectToAction("Search", new { searchString = "whatever" });
If it is a complex type, then you will need to store it in TempData. A number of other questions on StackOverflow (such as this one) give details on how.
If repeatedly storing to and reading from TempData across your application offends your code-sense, then you can encapsulate this by using the PassParametersDuringRedirect attribute and generic RedirectToAction available in the MvcContrib project. Some details on this technique are available here.
only way of doing post is by having a form and doing submit on that form, either with a submit button or with javascript, any info you want passed to that action must be in that form and you will find everything posted in FormCollection(hope I spelled it right).