Accepting Stripe payments with Android using ParseServer/Bitnami - java

I hope all is well. I'm fairly new to programming, and my school doesn't offer the appropriate level of Android Development to teach me what I need to know. So please do not mark this down because of "guidelines", I'm just trying to get some help. My instructors refuse to help because they aren't legally allowed to teach what is not offered. So please, please, please do not mark this down.
I am attempting to accept a Stripe payment on my mobile application. I am using ParseServer/Bitnami, and I have made it far enough to send and retrieve the tokenId to charge the card. I just haven't figured out how to charge the card. Please help.
Card userCard = new Card(num, expiryMonth, expiryYear, cvc);
// Test the data.
if (userCard.validateCard()) {
Stripe stripe = new Stripe(CardActivity.this, "pk_live_----REMOVED FOR SECURITY");
stripe.createToken(
userCard,
new TokenCallback() {
public void onSuccess(final Token token) {
// Get the current user.
ParseUser user = ParseUser.getCurrentUser();
String tokenId = token.getId();
// Update the token.
user.put("tokenId", tokenId);
/*Map<String, Object> params = new HashMap<>();
params.put("currency", "usd");
params.put("interval", "month");
params.put("name", "Membership");
params.put("amount", 9.99);
params.put("id", user.getObjectId());*/
user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Toast.makeText(CardActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
});
}
public void onError(Exception error) {
// Show error message
Toast.makeText(CardActivity.this,
error.getMessage(),
Toast.LENGTH_LONG
).show();
}
}
);
}

So to build a transaction or create a charge (either as a one-off charge or through a recurring subscription) there are actually two phases.
The first phase is called the "Capture and Tokenization Phase". That's where we use information about the credit card (or other payment source) to create a special string to represent the actual details of the card. I like to think of these tokens as more of a codeword (maybe I just watch too many movies)-- the Crow Flies at Midnight. It's a special way for both you and Stripe to know what card you're referring to, without anyone else being able to eavesdrop and figure out any sensitive information. You do this phase with Stripe.js [1], Elements [2], Checkout [3], or your mobile SDK [4][5].  This phase uses your Publishable API Key and happens on a front-end (HTML/Javascript or Mobile).
The second phase is the "Storing or Charging Phase". You can take that special token or codeword that we made earlier and then either (a) charge it for a particular amount of money or (b) attach it to a Customer and store it for later.  Either approach requires that you use the Stripe API on your backend. The alternative would be to use a Plugin or Integration to do all of this legwork for you.  This phase uses your Secret API Key and happens on a backend web service (PHP, Python, Ruby, etc.)
To create a recurring charge or attach the payment source to a Customer, you would use the Create a Customer [6] API Endpoint.  The source-argument would be the Token ID, generated in the first phase.  Then you would use the Create a Charge [7] API Endpoint with a customer-argument equal to the Customer ID you've created.
Alternatively, to create a one-off charge, you could simply pass the source-argument to the Create a Charge [7] API Endpoint without a customer-argument.
Meaning-- you're missing the last step here-- you need to pass your retrieved token to a backend server that you control to make the charge.
Hope that helps!
[1] https://stripe.com/docs/stripe.js/v2
[2] https://stripe.com/docs/elements
[3] https://stripe.com/docs/checkout
[4] https://stripe.com/docs/mobile/ios
[5] https://stripe.com/docs/mobile/android
[6] https://stripe.com/docs/api#create_customer
[7] https://stripe.com/docs/api#create_charge

Related

Android Billing how to use setAccountId or assign payment to custom identifier

I would like to **allow my users using my app across multiple devices **. Users have to log into my app through firebase auth.
Problem is that payments are assigned to account that is signed on the device (google play), not with account signed into the app.** From firebase auth I can get an email address of the user of my app - this could be used as some unique identifier.
Problem visualized:
I noticed that in Billing flow there is .setAccountId("some id") I think I could use this to fill in a unique identifier of a user. But how can use it querying purchases?
BillingFlowParams.Builder builder = new BillingFlowParams.Builder()
.setAccountId("some id")
.setSku(PREMIUM_YEAR_SUBS).setType(BillingClient.SkuType.SUBS);
TLDR: All I want to do is to retrieve purchases that are connected to my APP user account, not device account (google play currently logged in user).
To implement billing using accountId, try using the getBuyIntentExtraParams() method which provides additional functionality as compared with getBuyIntent() method.
With this method, you may use accountId with the following description:
Optional obfuscated string that is uniquely associated with the user's account in your app. If you pass this value, Google Play can use it to detect irregular activity, such as many devices making purchases on the same account in a short period of time.
Additionally, you may want to also check the typical purchase flow with the In-app Billing API discussed here.
It seems that we can't get the accountId, the accountId just used by google play.
I guess that you use the accountId to instead of the payload, but after my try, I think that it is not successful.
In the Google Billing Library, the develop payload is removed for the same experience between the in-app-purchase and the out-app-purchase. Though we can add payload in the period of consume or acknowledge, but it useless. And the payload should be set on the period of purchase, but google delete it, and will not be add back. The payload issues.
You can check the AccountId attached to each Purchase using
Purchase.getAccountIdentifiers
It'll return AccountIdentifiers object that has
AccountId & ProfileId that were set previously in BillingFlowParams when you launched billing flow
After that you can compare the current user account id with the account id attached to each purchase
to detect the purchases that are connected to the current user account

How to deduct an application fee from a charge object in Stripe API?

Customer1 is paying to Customer2 after the deduction of (platform fees + stripe Fees). To run such scenario. I did the following steps in Stripe-Connect:
Created a Customer1 object and added the card Info.
Created an account for a Customer2 using endpoint: https://stripe.com/docs/api#create_account
I can see the created account in Connected account section.
Verified the account after entering test Legal entity from the browser itself.
Creating a Charge object (Customer1 is paying) which also has an application_fee. The destination account mentioned in the request is newly generated Customer2 account.
I am using the Java API and it throwing me an error:
Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter).
I tried to follow up here on StackOverflow and it seems like I need to create a platform account to initiate such charges. If so, How can I create a Platform account?
How will it help me to charge the Customer1 and transfer the money to Customer2 connect account after the deduction of application_fee?
It sounds a bit confusing to me. Any help or hint would be appreciable.
You already have a platform account here. This is simply the word used to describe the main account (yours) that has connected accounts.
The issue here seems to be with the way you create the Charge. You can only take an application fee if you explicitly make that request on behalf of a connected account. There are currently 2 ways to do this:
Destination charges go through the platform and the funds are automatically sent to the connected account
Direct charges are created directly on the connected account and the application fee is sent back to you.
Since you are using Custom accounts where you create and own the accounts for your sellers you should use the first approach. In that case, you don't even have to take an application fee. Instead, you simply decide how much to send to the connected account when you create the charge. The idea is that you charge $100 and you only send $90 to the connected account so that you keep $10 for yourself (minus Stripe's fees).
The code would look like this:
// Create the list of parameters for the charge
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 10000); // amount to charge in cents
params.put("currency", "usd");
params.put("source", "tok_visa");
// Decide how what to send to the connected account
Map<String, Object> destinationParams = new HashMap<String, Object>();
destinationParams.put("account", "acct_XXXXX"); // connected account id
destinationParams.put("amount", 9000); // amount to send to the connected account
params.put("destination", destinationParams);
Charge charge = Charge.create(params);

Facebook Messenger bot object structure for java

Has anyone created an open source project that exposes the facebook messenger bot API in java? (or another language I could convert?)
Essentially an object hierarchy for the stack found in:
https://developers.facebook.com/docs/messenger-platform/send-api-reference
I'd rather not just use JsonObjects, etc. nor Maps to extract the incoming JSON chat messages or to build the outgoing structured chat replies. If an open source project for this exists -- I have not found it.
Take a look at FaceBot. The goal of FaceBot is making the Facebook's Messenger Platform easier: with FaceBot, you only need less than 5 lines of code to set up your own Messenger bot.
Here's an example:
public class MyFaceBotBehavior extends AbstractFaceBot {
public void defineBehavior() {
// Setting my tokens from Facebook (page token and validation token for webhook).
FaceBotContext.getInstance().setup("myFacebookPageToken", "myFacebookWebhookValidationToken");
// Defining a bot which will reply with "Hello World!" as soon as I write "Hi"
addActionFrame(new MessageEvent("Hi"),
new MessageAutoReply("Hello World!"));
}
}
If you have questions or need help, feel free to contact me (I'm the developer).
With the open source project messenger4j you will get all you need.
It's an easy to use Java library for building chatbots on the Messenger Platform.
It provides a rich builder API to construct the outgoing messages.
Furthermore it parses the inbound messages to specific java objects and automatically detects their type. For each message type or event you can register corresponding event handlers.
Receiving:
String payload = ... // callback request body
String signature = ... // 'X-Hub-Signature' request header
// JDK 8 version
MessengerReceiveClient receiveClient = MessengerPlatform.newReceiveClientBuilder("APP_SECRET", "VERIFICATION_TOKEN")
.onTextMessageEvent(event -> System.out.printf("%s: %s", event.getSender().getId(), event.getText()))
.build();
// JDK 7 version
MessengerReceiveClient receiveClient = MessengerPlatform.newReceiveClientBuilder("APP_SECRET", "VERIFICATION_TOKEN")
.onTextMessageEvent(new TextMessageEventHandler() {
#Override
public void handle(TextMessageEvent event) {
System.out.printf("%s: %s", event.getSender().getId(), event.getText());
}
})
.build();
receiveClient.processCallbackPayload(payload, signature);
Sending (simple):
MessengerSendClient sendClient = MessengerPlatform.newSendClientBuilder("PAGE_ACCESS_TOKEN").build();
sendClient.sendTextMessage("RECIPIENT_ID", "Hi there, how are you today?");
Sending (complex):
ReceiptTemplate receipt = ReceiptTemplate.newBuilder("Stephane Crozatier", "12345678902", "USD", "Visa 2345")
.orderUrl("http://petersapparel.parseapp.com/order?order_id=123456")
.timestamp(1428444852L)
.addElements()
.addElement("Classic White T-Shirt", 50F)
.subtitle("100% Soft and Luxurious Cotton")
.quantity(2)
.currency("USD")
.imageUrl("http://petersapparel.parseapp.com/img/whiteshirt.png")
.toList()
.addElement("Classic Gray T-Shirt", 25F)
.subtitle("100% Soft and Luxurious Cotton")
.quantity(1)
.currency("USD")
.imageUrl("http://petersapparel.parseapp.com/img/grayshirt.png")
.toList()
.done()
.addAddress("1 Hacker Way", "Menlo Park", "94025", "CA", "US").street2("").done()
.addSummary(56.14F).subtotal(75.00F).shippingCost(4.95F).totalTax(6.19F).done()
.addAdjustments()
.addAdjustment()
.name("New Customer Discount")
.amount(20.00F)
.toList()
.addAdjustment()
.name("$10 Off Coupon")
.amount(10.00F)
.toList()
.done()
.build();
sendClient.sendTemplate("RECIPIENT_ID", receipt);
BTW: I've built it.
I am currently working on a bot framework in java called JBot and the fb portion is currently under development but the Slack part is done and is used by several developers already.

How to provide other members’ information to users through Facebook Graph API

I’m making a dating application that provides ‘members’ information (Facebook profile) to a user’ just like other dating applications. And I used Facebook Graph API below but I would like someone to tell me about ‘how to provide other members’ information to a user’.
Firstly, I registered my application in Facebook developers
I was approved with functions I need to use through 'Submit Items for Approval' (my Approved Items: email, public_profile, User_photo, User_like, user_work_history, user_education_history)
Then, I created member DB through a server and as a result, I can check all users’ ID with interlocked Facebook login.
So if a user logs in with her/his account in my application, (s)he can call her/his detail information in the account. (User_photo, User_like, user_work_history, user_education_history)
But the problem is, the user needs to receive members’ information around him/her (User_photo) but it doesn’t seem to work. (public_profile information can be provided)
It means, after receiving the user’s ID, it is forwarded to a server to use {user-id}/albums and {user-id}/photos call source. But it still says there is no result for both. (Brings GraphUser information through Facebook login and brings user_id through GraphUser.getId() )
So I am wondering if only the information in the ID section of logged in account is visible, but it seems an application called highli*** is using the service.
I would like to request someone to help me to solve the problem of # 5,6? Please help me (Please see the source)
Bring album_id through the method below by using user_id information
new Request(Session.getActiveSession(), "/user_id/albums", null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
} }).executeAsync();
Bring photo information through the method below by using album_id information
new Request(Session.getActiveSession(), "/album_id/photos", null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
} }).executeAsync();
If the Facebook Graph API is returning no results (an empty array) then more than likely it is a permissions issue.
In order for you to access another user’s information, the other user must also have given the required permissions.
For example:
User A is requesting the information of User B. Both users must grant the permissions below for the following requests:
user_friends, user_photos
{UserB-Id}/albums
{UserB-Id}/photos
{Album-Id}/photos
I suggest using the Graph API Explorer to test your requests. Here you can mock a token for your app and also apply different permissions, even before Facebook gives you approval to use them.
You can find more info on permissions here.

How can I integrate Paypal to payout users when a button is clicked?

It might sound a little odd but I am in the final phases of finishing up my app that would pay users.
There is an activity in the app where as and when the users use the app, money keeps accruing. I have a button in that activity called Cash Out which when the user reaches a certain amount can be clicked and is supposed to let the users take the money accrued from the app.
I have contacted Google Checkout and Paypal so far and Paypal suggested personal payments can be integrated in my case and sent me the Paypal for Android API doc. The doc itself is very useful but does not describe this kind of a scenario that I am looking for. Any clues how to integrate such a functionality. I appreciate anyone willing to help me out.
Wow!! Big challenge now. Paypal Technical Support and my conversation thread below: They don't support this functionality yet. So I guess I have something in my hand that has not been done.
Customer 11/03/2010 01:05 PM
I had a feeling that this feature is not supported by any vendor like PayPal or Google Checkout since it is payment processing the other way round which has never been done before in an App.
So let me ask you this since this is a major functionality in the app and we have to do this ASAP here is the question.
We have data of the users' email address and how much cash needs to be sent to each one of them. Can we run a batch job from the server and send data to Paypal with the User email addresses and amounts to process the payments. If yes please let me know how is that possible?
Thanks for your help.
Response (Vivek) 11/03/2010 12:42 PM
Hi ,
As mentioned in the "MPL Developer Guide and Reference - Android OS Edition" (that comes in Documentation with Library package), Page 32, which has only to do with Fees.
Unfortunately, right now it is not possible to functionally achieve the requirement of being able to initiate receive transaction from ones own device and being able to receive money via the app.
However, your idea is very thought provoking and it would be great if you could give more information on businesswise what you are trying to achieve and I can escalate this and see if it qualifies for future feature request.
Thanks,
Vivek
Customer () 11/03/2010 10:57 AM
By the way we are using the Mobile Payments Library for Android and Type Personal Payments which was suggested by a Paypal Tech Rep w.r.t my last question.
Here is the code snippet.
CheckoutButton launchPayPalButton = ppObj.getPaymentButton(PayPal.BUTTON_278x43, this, PayPal.PAYMENT_TYPE_PERSONAL);
Thanks.
Customer () 11/03/2010 10:53 AM
Your question#1
You had mentioned that you want to send user (user of the android app) the money from the Android device the user himself is using and the money comes from the your account. Is this true? -
Answer #1
That is CORRECT.
Your Question # 2
"If this is the case, why cannot you set the above android user and recipient and you login and send money.
But if I am right you want the above android user to initiate the operation and to take money from your account. Technically speaking, you want to do retrieve money and not a send money in some way, is this true?"
My Answer # 2
Since the Android App user initiates the transaction from his phone app there is no way I can login at that time from his phone. So your understanding is CORRECT that we want the user to initiate the operation and to take money from our account and we will set how much and what email address gets it programmatically from the App.
So basically YES we want the App user to retrieve money from our account and not pay us.
Response (Vivek) 11/03/2010 10:46 AM
Hi ,
Thank you for contacting us and we are glad to be of assistance to you.
I am currently researching on your question and will give you an update ASAP. Meanwhile, I have a few clarifications on your question:
Q: When testing the code in Paypal Sandbox environment we notice that everytime the button is clicked the recipient and the amount is set as we want but it brings up the login screen.
* Yes, you set the amount and recipient in the code programmatically. The login it asks for is the sender of the transaction. Can you please verify which button or operation you are trying to do?
The whole purpose of having an Android app for business
You had mentioned that you want to send user (user of the android app) the money from the Android device the user himself is using and the money comes from the your account. Is this true?
If this is the case, why cannot you set the above android user and recipient and you login and send money.
But if I am right you want the above android user to initiate the operation and to take money from your account. Technically speaking, you want to do retrieve money and not a send money in some way, is this true?
Please clarify.
Thanks,
Vivek
Customer () 11/03/2010 08:19 AM
Hi,
We are currently testing Paypal Integration functionality for our Android Application where we want Users to use paypal to receive accrued cash from our account.
We have set up the Sandbox environment and following is the code we have used.
Here is the problem.
Once the user of the App clicks the Paypal button we want to programatically set the amount and the recipient email from the App as to who and how much can be taken out from our bank account.
newPayment.setAmount("10.00"); //lets say 10USD.
newPayment.setRecipient(""); //sandbox email setup as a personal account.
When testing the code in Paypal Sandbox environment we notice that everytime the button is clicked the recipient and the amount is set as we want but it brings up the login screen. I dont understand how can we make this work? Remember in this case we want to preauthorize the recipient to take accrued money from our account through paypal checkout button and not the other way round.
This is basically a personal payment situation where we want to send money to the user and not receive from the user of the App. Please let us know what is a possible resolution to our problem?
If this does not work is there any other way we can use Paypal to pay Android App Users using their email address. Once again this is not a normal checkout situation where the person checking out pays the business.
PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX);
CheckoutButton launchPayPalButton = ppObj.getPaymentButton(PayPal.BUTTON_278x43, this, PayPal.PAYMENT_TYPE_PERSONAL);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.refresh);
params.bottomMargin = 10;
launchPayPalButton.setLayoutParams(params);
launchPayPalButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PayPalPayment newPayment = new PayPalPayment();
newPayment.setAmount("10.00");
newPayment.setCurrency("USD");
newPayment.setRecipient("");
newPayment.setTax("0.00");
newPayment.setShipping("0.00");
newPayment.setItemDescription("Your Payment");
newPayment.setSenderEmail("");
newPayment.setMerchantName("My Test Store");
Intent paypalIntent = new Intent(getApplicationContext(), PayPalActivity.class);
paypalIntent.putExtra(PayPalActivity.EXTRA_PAYMENT_INFO, newPayment);
UrMoney.this.startActivityForResult(paypalIntent, 1);
}
});
((RelativeLayout)findViewById(R.id.urmoney1)).addView(launchPayPalButton);
Thanks for the help.

Categories

Resources