I am integrating Stripe on Android and I have imported a GitHub project from https://github.com/stripe/stripe-android
I did not understand how to send the generated tokens to my server after my card is validated. I found some codes but they were not helpful.
Any help will be appreciated!
Stripe is very easy payment gateway for implementation.
Very first you have to create Stripe Token from your Android App.
After generating token, you have to get TokenId from that token. for that you can use "id" key and save this as a Sting form JSON which was given by stripe:
JSON example :
com.stripe.model.Token JSON: {
"id": "tok_189gBz2eZvKYlo2Cm2Z3qsT2",
"object": "token",
"card": {
"id": "card_189gBz2eZvKYlo2CBZAUeFKj",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": null,
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2017,
"fingerprint": "Xt5EWLLDS7FJjR1c",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": null,
"tokenization_method": null
},
"client_ip": null,
"created": 1462907211,
"livemode": false,
"type": "card",
"used": false
}
In above example "id": "tok_189gBz2eZvKYlo2Cm2Z3qsT2" is your TokenId.
Now save this TokenId as a String and pass it to your back-end PHP/.net/Java server using web services. simply create one post service in which you can send this TokenId and other optional details about payment. and you can call this web service using Retrofit or volley .
You need one web service form your back-end. so create one web-service using PHP or whatever you use for back-end.and pass this String to server.
Once you already have a Stripe token, you can just get the token ID (Token#getId()), which is just a String and send it to your server however you like. (Wrap it in JSON, etc)
That token ID is all you need to make a charge. There are plenty of libraries that can help you with your IO needs, such as Volley and Retrofit.
Related
I'm new to Stripe and payment integration in general.
I would like to implement a payment system in my application. I have already set the credit card input, which is also verified by creating a token of this type:
{
"card": {
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": "unchecked",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2025,
"funding": "credit",
"id": "card_1HZFtCHAdtJCId9lZP626zJI",
"last4": "4242",
"name": null,
"object": "card",
"tokenization_method": null
},
"client_ip": "5.171.212.113",
"created": 1601989654,
"id": "tok_1HZFtCHAdtJCId9lxdU1jFVa",
"livemode": false,
"object": "token",
"type": "card",
"used": false
}
so far so good, what I should do is send this token to my php server (an external hosting without any particular library installed). Can anyone explain to me how to process the payment from back-end? I checked the documentation but none of them explain how to do it using a normal php hosting. I thank everyone in advance for taking the time!
Data Source: https://stripe.com/docs/api/
Considering you have already installed stripe you would follow these steps.
If not you should use composer to install it.
composer require stripe/stripe-php
1)Authentication
The Stripe API uses API keys to authenticate requests so you must auth first using your API keys to use anything. https://dashboard.stripe.com/login?redirect=/account/apikeys
$stripe = new \Stripe\StripeClient(INSERT_API_KEY_HERE);
2)Create a charge
You already got your card so you can charge it.
Edit: You can get all the data you need by making a request using the api. By the time you create a user in your app, you should also create a Customer using stripe and save their stripe-id in your database so you can access to their data.
Creating a customer
$customer = $stripe->customers->create(['description' => 'My First Test Customer',]);
// Save your customer ID using $customer->id
Charging the card
$stripe->charges->create([
'amount' => 2000,
'currency' => 'usd',
'source' => 'INSERT_CARD_ID',
'description' => 'My First Test Charge',
]);
Source:
A payment source to be charged. This can be the ID of a card (i.e., credit or debit card), a bank account, a source, a token, or a connected account. For certain sources—namely, cards, bank accounts, and attached sources—you must also pass the ID of the associated customer.
While #Juan has answered above using the Charges API, for an integration which supports Strong Customer Authentication I would recommend using the Payment Intents API.
You can read through the end-to-end guide for creating a payment which includes both client and server code snippets in a variety of languages (including PHP). This is the recommend pattern.
Since you already have a card_123 if you want to attempt payment without SCA support, you can actually go right to creating the payment:
\Stripe\PaymentIntent::create([
'amount' => 1234,
'currency' => 'usd',
// 'customer' => 'cus_567', // only if you've attached the card
'payment_method' => 'card_123',
'error_on_requires_action' => true,
'confirm' => true,
]);
I am trying to make an android app for a wordpress website. But unable to get the JSON of post. I tried with two pluginsThese are the plugins of the website
for JSON
WP Rest API
JSON API
WP Rest API is returning this
[]
and JSON API is returning this
{
"status": "ok",
"count": 0,
"pages": 0,
"category": {
"id": 21,
"slug": "maths",
"title": "Maths",
"description": "",
"parent": 13,
"post_count": 3
},
"posts": []
}
According to me this problem is due to any other plugin. But I am unable to find the solution
API using for JSON
1. with JSON API plugin I am using this link http://iitianlogic.com/custom/get_category_posts/
and posting id=4
The request url is not correct, Please try the below url which showing posts under uncategorized category http://iitianlogic.com/api/core/get_category_posts/?slug=uncategorized
Hope this will work
How can we use this json for php?
$ curl ipinfo.io
{
"ip": "178.78.135.10",
"hostname": "No Hostname",
"city": null,
"region": null,
"country": "AM",
"loc": "40.0000,45.0000",
"org": "AS49363 Orange Armenia CJSC"
}
I've found this at here : http://ipinfo.io/
Use file_get_contents to fetch the data and json_decode to turn it into php.
$data = json_decode(file_get_contents("http://ipinfo.io/"));
print_r($data); /* print results */
Using this server-side (i.e. PHP) will display your server's IP and information, not the user's.
If you want information on the user, you need to use JavaScript to implement their JSONP API to have the user's browser call the API and return info on the user's IP.
Alternatively, you need to call their API for the user's IP:
$data = json_decode(file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/json"));
I am trying to add event tracking to a product that is being translated to html cross-domain...
The file is located server-side and written in PHP. The JSON snippet that I need to append the GA event to is as follows:
"products": [
{
"title": "product",
"description": "description",
"thumbnail": "http://myurl.com/picture.jpg",
"price": "£1.99",
"url": "http://link.com"
},]
Now, reading up a little bit on this on this article has given me a bit of insight: Using google analytics to track hits on an XML web service
Would it be a matter of something as simple as this?
<?php
//Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com');
?>
"products": [
{
"title": "product",
"description": "description",
"thumbnail": "http://myurl.com/picture.jpg",
"price": "£1.99",
"url": "http://link.com"
},$ga->setEvent("Category", "Action", "Label", "Value");]
Sure, look at mit Github Project
https://github.com/ins0/google-measurement-php-client
it is a PHP client library to communicate with Google Analytics from server-side.
otherwise you can use other great repositorys, look here
https://github.com/search?q=google-measurement&source=cc
I'm currently writing a PHP application.
I noticed something strange when it wasn't returning the persons birthday.
To cut a long story short, when i manually query the graph api, it gives me the full result set (birthday, email etc. included). However, when I run it in my app, it comes back as if i've not sent the access token.
When I manually visit the address it produces:
{
"id": "507665705",
"name": "Ally Dewar",
"first_name": "Ally",
"last_name": "Dewar",
"link": "https://www.facebook.com/alastair.dewar",
"username": "alastair.dewar",
"birthday": "06/22/1990",
"location": {
"id": "113744028635772",
"name": "Greenock"
},
"gender": "male",
"email": "alastair\u0040alastairdewar.co.uk",
"timezone": 1,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-03-11T15:56:19+0000"
}
However, when my application makes the same request (exact same URL), it comes back with
{"id":"507665705","name":"Ally Dewar","first_name":"Ally","last_name":"Dewar","link":"http:\/\/www.facebook.com\/alastair.dewar","username":"alastair.dewar","gender":"male","email":"alastair\u0040alastairdewar.co.uk","locale":"en_GB"}
My instinct says it could be a setting within the facebook app, as it wasn't a problem beforehand.
EDIT: https://developers.facebook.com/bugs/412680422092698?browse=search_4f854dc037a2a5d12811839
Thanks for any advice.
Make sure you ask for all the permissions that you need and also remove the app and start again. Make sure you ddon't cache any of the responses as well.
How do you query the API? Graph Explorer or just manually open the link (graph.facebook.com/USER_ID) and pass the auth token generated by the app? Testing with the Graph Explorer won't help you with your problem as permissions etc are different.
As mentioned by Nobita, code helps. This is as much as I can advise considering the amount of data you're giving us.