Edit:
After paypal login, I could successfully complete transaction.But I need to match the successUrl in paypal to verify both url is same and
As mentioned above,
u need to check response json object. if state is approved that means paypal payment is successful.then you can check on Paypal website for current transactions
Edit
It seems from the screen shots you're embedding a subscription page into your webview, and trying to match successUrl
with the return URL.
Check the answer in this post to set up the retrun URL first in your profile
Obtain the URL String webUrl = webView.getUrl();
if you want to make match/ verification with the defined successUrl
I am getting a Payment success or failure request using this below Codes:
private void loadWebViewPaypal() {
payUrlStr = LOAD_WEBVIEW_PAYMENT_PAYPAL(PAGE_ID);
Log.e("payUrlStr", "" + payUrlStr);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(payUrlStr);
@SuppressWarnings("unused")
WebSettings settings= webView.getSettings();
if (Build.VERSION.SDK_INT >= 21) {
webView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}
}
public class WebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.e("Page Started", ""+url);
super.onPageStarted(view, url, favicon);
if(url.contains(successUrl)) {
Log.e("Getting Success Request", "Test");
Intent i = new Intent(PaypalWebActivity.this, TabhostActivity.class);
PAYPAL_WEB_BACK = "fulfilled";
startActivity(i);
finish();
} else if(url.equalsIgnoreCase(failureUrl)) {
Intent i = new Intent(PaypalWebActivity.this, TabhostActivity.class);
PAYPAL_WEB_BACK = "fulfilled";
startActivity(i);
finish();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e("Override Url", ""+url);
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
Log.e("Finished Url :", "" + url);
if(dialog.isShowing()){
dialog.dismiss();
}
}
}
What I understand with your query is, you have an URL of your Website which perform payment using Paypal, and in Mobile app you are performing the same using the Webview(not Paypal SDK).
Yes, you can get the callback
by doing some coding at your WEB end.
Meaning:
Whenever any user navigate to Payment page then your Server must know whether User visited from Website or through Mobile Webview, Server can send additional parameter key
to any Payment gateway for their custom logic. Later once Payment transaction completed, Payment gateway will return the same additional parameter key
alongwith the result(Success or Failure).
Note: Every Payment gateway has a setting of Redirection url for Success/Failure
Once Paypal redirect to result url(Success/Failure) after Transaction gets completed, Server then again check whether the request has been made from Website or from Mobile Webview with the help of additional parameter key
; check case below...
If from Mobile Webview
www.myserver.com/success
www.myserver.com/failure
If from Webiew then Normal flow
Now in your Mobile's Webview
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
if(url.equalsIgnoreCase("www.myserver.com/success"))
//Success Toast
else if(url.equalsIgnoreCase("www.myserver.com/failure"))
//Failure Toast
return true;
}
});
That's it.
Paypal returns json response after successful payment like below
{
"client": {
"environment": "sandbox",
"paypal_sdk_version": "2.14.1",
"platform": "Android",
"product_name": "PayPal-Android-SDK"
},
"response": {
"create_time": "2016-06-15T11:38:04Z",
"id": "PAY-6CN54299U76194116K5QT4BY",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}
You need to check response json object. if state is approved that means paypal payment is successful. Then you can check on Paypal website for current transactions.
Make Sure you have followed below steps:
1)
private static final int REQUEST_CODE_PAYMENT = 1;
private static String CONFIG_ENVIRONMENT=PayPalConfiguration.ENVIRONMENT_SANDBOX;
//It will be PayPalConfiguration.ENVIRONMENT_PRODUCTION for live mode.
2)
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID = "ATBvU5urlaPOhpCrAhFsoG4u63RvNoKUocFPs9yR5q_sbM0yecZawUjoJhIilW8DNg5RrJcRHgRuEP_1";
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Example Merchant")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
Intent intent = new Intent(getActivity(), PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
getActivity().startService(intent);