Make payment with stripe from Card - php

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,
]);

Related

Create charge using Stripe in Laravel working in test mode but not in live

Hope somebody can help me with this one.
I am clueless right now.
I just started stripe for the first time.
Looks like an amazing service.
Have created a test application and started testing.
Everything works as it should.
Now after signing up, I want to go live.
Here is where the problem occurs.
Somehow, it keeps saying no such token, when I can see the token standing in the stripe account. The id of the account and our database is completely the same.
Stripe::setApiKey('[our live token]');
/*
* create new customer
*/
$results = \Stripe\Charge::create([
"amount" => '10',
"currency" => "jpy",
"source" => $getCommission->unique_id,
"description" => "test charge"
]);
Anybody has ever experienced this?
It keeps saying the following
No such token: cus_EuguGZgeDoCxBj
Help is highly appriciated.
Wesley
You are providing customer id instead of source token.
Source Token :
Source token is token which is used for referenced of your cards. Generated from Stripe.js
\Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
\Stripe\Charge::create([
"amount" => 2000,
"currency" => "usd",
"source" => "tok_amex", // obtained with Stripe.js
"description" => "Charge for jenny.rosen#example.com"
]);
How to get Default Source :
Get Stripe Customer
Get default source on the Behalf of that customer
\Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
$customer = \Stripe\Customer::retrieve('cus_EkSwM3JX7f0ueA');
$customer->default_source; // use this as source token
Use default source as source token

How to check "remote area" for an order in FedEx API | Laravel | PHP

I am using "Arkitecht/fedex-laravel" package in Laravel. I have implemented create the shipment and many more. Now my requirement is to check the remote area for an order. Which FedEx API is used to get my desired result. I do not find anything on FedEx documentation.
You'll get Surcharges variable in your response.
"Description": "Out of delivery area" => This line denotes Remote Area.
"Surcharges": [
{
"SurchargeType": 50,
"SurchargeTypeSpecified": true,
"LevelSpecified": false,
"Description": "Out of delivery area",
"Amount": {
"Currency": "SID",
"Amount": 32.3
}
},

Stripe - Manual payout

In my application i'm holding some amount in user's custom account for a specific reason by setting "Payout schedule" as "Manual". This lets me hold the payout in custom acccount to a maximum of 90 days. And a user can realease the payment to the external account in certain scenerios even before 90 days.
Now my Question is, As Stripe takes 2 to 7 days in rolling out the payment so i can only release the payment after the processing gets completed.
How May i get to know about that? How would i know if the tranactions is in pending state and then How to know if it gets available for payout in bank account?
Is there any way to achieve it? Please let me know as im new to stripe.
Any help would be highly appreciated.
Are you talking about Auth and Capture? Auth is when you make sure that the user's bank ALLOWS the user to make the transaction. Then, once the payment is Authorized, you then capture it, and the funds are transferred to Stripe.
Example: You are selling a service, such as Web Development, for $5000. You want to make sure that the person has the money first. You also want to make sure that the person who has the money doesn't spend it while you are rendering your service for them.
The way you would go about this is to:
Auth the payment through Stripe. You Auth the payment, and it goes into Pending in the person's bank account (they don't have access to spend that money any longer).
Render your service
Capture the payment. The money is deducted from their account and added to your Stripe account.
The way through Stripe's API to do this is: Auth
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
// Charge the user's card:
$charge = \Stripe\Charge::create(array(
"amount" => 999,
"currency" => "usd",
"description" => "Example charge",
"capture" => false,
"source" => $token,
));
Render your service... Then Capture
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
$charge = \Stripe\Charge::retrieve("ch_1A9eP02eZvKYlo2CkibleoVM");
$charge->capture();
When you create the charge it will return an ID in the JSON results and whether or not it's been captured. If you want to check up to see if the Auth was successful, first save the ID in the response to the charge... The response will look something like this...
Stripe\Charge JSON: {
"id": "ch_1CCjK02eZvKYlo2C85c1GGmL",
"object": "charge",
"amount": 2000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
"captured": false,
......... more ........
},
To check on the charge, to see if it has been Authorized, you can do something like this...
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
\Stripe\Charge::retrieve("ch_1CCjK02eZvKYlo2C85c1GGmL");
And the response will be something like ...
Stripe\Charge JSON: {
"id": "ch_1CCjK02eZvKYlo2C85c1GGmL",
"object": "charge",
"amount": 2000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
"captured": true,
"created": 1522739568,
....more....
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"seller_message": "Payment complete.",
"type": "authorized" // AUTHORIZED
Then you charge. Done.
https://stripe.com/docs/charges

How to send Stripe Tokens to our Server from android application?

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.

Stripe connect and PHP / Magento

I use Inchoo's extension for connecting Magento and Stripe payment. Inchoo component is simple and it is based on https://github.com/stripe/stripe-php. When I use it for test payments it works as it should be.
But I need stripe connect because of 'application_fee' and I now have problem.
According tutorial stripe.com/docs/connect/oauth I use https://gist.github.com/afeng/3507366
and everything still works great.
According stripe.com/docs/connect/collecting-fees :
We have following code -
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
$charge = Stripe_Charge::create(array(
"amount" => 1000, // amount in cents
"currency" => "usd",
"card" => $token,
"description" => "payinguser#example.com"),
"application_fee" => 123 // amount in cents
),
**ACCESS_TOKEN** // user's access token from the Stripe Connect flow
);
But ACCESS_TOKEN is problem, because I use the one that I get in previous step 'stripe.com/docs/connect/oauth'
and get error:
OAuth based requests must use card tokens from Stripe.js, but card details were directly provided.
Why and where I should use Stripe.js? Everything works great until 'ACCESS_TOKEN' is requested and it says :
// user's access token from the Stripe Connect flow - I already have ACCESS_TOKEN
from
(stripe.com/docs/connect/oauth)
{
"token_type": "bearer",
"stripe_publishable_key": PUBLISHABLE_KEY,
"scope": "read_write",
"livemode": "false",
"stripe_user_id": USER_ID,
"refresh_token": REFRESH_TOKEN,
"access_token": ACCESS_TOKEN
}
problem w

Categories