Capture Paypal Payment in android - android

I have authorized Paypal amount using PayPalPayment.PAYMENT_INTENT_AUTHORIZE intent in PaymentActivity now i have authorizationId but how to capture this amount now?
Code to start PaymentActivity
PayPalPayment thingToBuy = getStuffToBuy(PayPalPayment.PAYMENT_INTENT_AUTHORIZE);
/*
* See getStuffToBuy(..) for examples of some available payment options.
*/
Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
// send the same configuration for restart resiliency
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
onActivityResult
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
ProofOfPayment proof = confirm.getProofOfPayment();
PayPalPayment payment = confirm.getPayment();
payment.enablePayPalShippingAddressesRetrieval(true);
JSONObject object = proof.toJSONObject();
String authID = "";
try {
authID = object.getString("authorization_id");
} catch (JSONException e) {
e.printStackTrace();
}
if (confirm != null) {
try {
Log.i(TAG, confirm.toJSONObject().toString(4));
Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
/**
* TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
* or consent completion.
* See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
* for more details.
*
* For sample mobile backend interactions, see
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
displayResultText(authID);
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(
TAG,
"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}
Now I have authorization id in authId now i want to capture this amount. Can I do this within my app without any server side work.

Make a post request to https://api.sandbox.paypal.com/v1/oauth2/token
2.Set the Authorization type to Basic Auth and then set the client_id into the Username field and secret into the Password field.
3.Set the Body to x-www-form-urlencoded and then set grant_type in the key field and client_credentials in the value field.
In response to above you will get an access token.
Now make GET request to https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI with Headers, Content-Type -- application/json" and Authorization -- Bearer accessToken_you_get_in_above_call .(PAY-5YK922393D847794YKER7MUI this is your payment id)
In response of above you will get an object as "state": "approved", if it is approved means your payment has been successfully done.
Note:- In the first response you will get an access token, but this token is valid for only few seconds , so you have to get another access token if it is expired.
For more details refer:- https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ https://developer.paypal.com/docs/integration/direct/make-your-first-call/

Related

Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0

I am implementing the new billing API 2.0 which has this purchase acknowledge method.
Earlier i was using AIDL for my purchase and i had following use case is that i used to pass developer payload during initiating purchase and used to get back my developer payload in the response as a part of purchase object.
Bundle bundle = mService.getBuyIntent(3, "com.example.myapp",
MY_SKU, "subs", developerPayload);
PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
// Start purchase flow (this brings up the Google Play UI).
// Result will be delivered through onActivityResult().
startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
and in my on on activity result i used to get purchase object
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
This purchase object has a developer payload which i send to the server for verification.
Now in the new API the developer payload can be added only after purchase is completed or when we consume a purchase, so the problem is after purchase is acknowledged i need the updated purchase object but how to get it?
if (!purchase.isAcknowledged()) {
AcknowledgePurchaseParams acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken())
.setDeveloperPayload(/* my payload */)
.build();
client.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
}
In acknowledgePurchaseResponseListener i get only the response code whether it is success or failure. But i need to updated purchase object object with developerPayload and isAcknowledged flag true.
Is there a way to do so? Could not find anything in documentation.
The local cache of purchases is updated by the time your acknowledgePurchaseResponseListener is called so you can query the purchase from the cache using https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#querypurchases. We will consider adding the update purchase to the listener for a future library release to make this more convenient.

How to authorize multiple paypal account for future payment?

in my Android application I want to use paypal for payment and user will login once and will pay any time without login when it want for that I am using following code of paypal SDK
Intent intent = new Intent(MainActivity.this,
PayPalFuturePaymentActivity.class);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
and receiving auth code in onActivityResult like this
if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
and doing further process to payment up to this I have no any problem.
But now I want to give option to users that they can set more than one paypal account and at time of pay app will ask them to choose an account from which they want to pay from their saved accounts.
is it possible please suggest me better idea.

Android InAppBilling PurchaseStatusAPI

I want to establish a content provider server whose different contents have to be bought using the Android InAppBilling API. If a mobile user buys an item he gets a unique purchase token. If the user wants to download some content from my server I can use that token to check if the purchase is valid and thus the user is allowed to download the content.
But how do I check if that purchase token really belongs to the user my server is talking to? Is there an existing authentication mechanism?
as you can see at the end of image there are "response code" you can use it like developer docs
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
if not enough also you can check In-app Billing Reference (IAB Version 3)
well I am trying to help not a prof..

Getting payment configuration from PayPal lib

I'm using PayPal in my monodroid application. I used the libraray that has been shared in this topic: http://forums.xamarin.com/discussion/comment/15331/#Comment_15331
But i have a problem at getting PaymentConfirmation object at OnActivityResult method. This is my code:
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Ok ) {
var confirm = data.GetParcelableExtra ("com.paypal.android.sdk.paymentConfirmation") ;
PaymentConfirmation pc = (PaymentConfirmation)confirm;
if (confirm != null) {
try {
//Log.Info ("paymentExample", confirm.ToJSONObject ().ToString (4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.\
} catch (JSONException e) {
Log.Error ("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}else if (resultCode == Result.Canceled ) {
Log.Info ("paymentExample", "The user canceled.");
}else {
Log.Info ("paymentExample", "An invalid payment was submitted. Please see the docs.");
}
}
at the third line of the method. Compiler can not cast confirm to PaymentConfirmation. Do I need any other classes or codes in order to use data.GetParcelableExtra?
As written in a comment JavaCast should be used in this case. I think this happens when the binding generated for the type, does not contain a GetType method. Hence .NET does not know what to cast it to.
So your line:
PaymentConfirmation pc = (PaymentConfirmation)confirm;
will need to be:
PaymentConfirmation pc = confirm.JavaCast<PaymentConfirmation>();

post NOT predifined messages on facebook wall from android application

I'm trying to create an android application which would allow the users to post messages on their facebook wall and also on their friends wall.
I've been through a few tutorials but in each of them is done barely the same thing:integrate facebook in application, the login authorization and posting a predifined message on the walll.
I'm using facebook sdk and I wonder is possible for the user to write directly to his wall in a dialog window???
What kind of authorization I need and if u could give me an example would be great.Thank u!
Take a look at this tutorial here and there is part 2 here. It will guide you though setting up the application to use facebook. Once you have all that setup you can use a function like this to post a msg to someones wall:
/**
* Post to a friends wall
* #param msg Message to post
* #param userId Id for friend to post to or null to post to users wall
*/
public void postToWall(String msg, String userID) {
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle parameters = new Bundle();
parameters.putString("message", msg);
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", parameters, "POST");
Log.d(TAG,response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
} catch(Exception e) {
e.printStackTrace();
}
}

Categories

Resources