Stripe payment issue with "application fee" - php

I am facing following problem while doing stripe payment.
Uncaught exception 'Stripe\Error\Authentication' with message 'Only Stripe Connect platforms can work with other accounts. If you specified a client_id parameter, make sure it's correct
I am using the php code below:
$charge = \Stripe\Charge::create(
array(
"amount" => $amount*100, // amount in cents
"currency" => $currency, // usd
"source" => $token,
"description" => $description,
"application_fee" => 123 // amount in cents
),
array("stripe_account" => 'cus_7Gt1CAXXXXXX') // CONNECTED_STRIPE_ACCOUNT_ID
);
And another question is that from where I can get CONNECTED_STRIPE_ACCOUNT_ID like that acct_12QkqYGSOD4XXXXXX. if possible please send code or screenshot or location to get these account id.
Can anyone please help to solve that problem?

You have to create 'Connect with Stripe' button in your app which will redirect user to fill form to authorize your app.
After Clicking on Authorize button(by user,after filling form properly), it will redirect to 'Redirect URI(redirect URI is that URI which you fill in Platform Setting)'.
After redirection stripe will add scope and authorization code to your URI
for eg. your URI: www.yoursite.com
you will get www.yoursite.com?scope=read_write&authorization_code=AUTHORIZATION_CODE
After That follow----> https://stackoverflow.com/a/34714859/5467417

Related

Testing Stripe - Creating charge for Checkout session

I'm using Stripe checkout and I have it all working as follows:
Create Session, redirect to Checkout, handle order fulfillment on redirect with passed through session_id.
I'm trying to write a test for this but I can't figure out how to fake a Stripe Checkout charge onto the Stripe Session & PaymentIntent.
I'm using the PHP Library and I've tried this:
$paymentIntent = PaymentIntent::retrieve($session->payment_intent);
dd($paymentIntent->charges->create([
'source' => 'tok_visa_debit',
'currency' => 'gbp',
'amount' => 100,
]));
But I am getting an error: Stripe\Error\InvalidRequest : Received unknown parameter: payment_intent
What is the correct way to test this works?

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

Verify stripe payment amount

For my shopping site I have a fairy simple stripe implementation on the frontend where user hits "pay through stripe" button fills in CC details in a popup and hits proceed. If all goes well I get a token as $_POST['stripeToken'] which I process like below (for web payments)
try
{
$stripe = new Stripe();
$stripe = Stripe::make();
$customer = $stripe->customers()->create([
'email' => $_POST['email_id'],
'source' => $_POST['stripeToken']
]);
$charge = $stripe->charges()->create([
'customer' => $customer['id'],
'amount' => $total_amount, // note this is calculated again on server to prevent fraud
'currency' => 'sgd'
]);
}
catch (\Cartalyst\Stripe\Exception\CardErrorException $e)
{
return view('front.payment_error')->with('message', $e->getMessage());
}
Thing is we cannot rely on $total_amount coming from frontend form submission as user can easily spoof this amount and pay just $1 in stripe and get a token and spoof $total_amount to 1 thus getting products at whatever price he wants ,that's why I need to calculate his `$total_amount again on the server (from his cart) and use that to process stripe on the server.If that amount doesn't match what the token stands for , stripe would automatically raise an exception and prevent fraud.
So far good.. but the problem comes when dealing with API , mobile app will process stripe using their own libs. on the client side they would just send the final (for recording in db) but obviously I cannot use it to charge since that is already done on the mobile.Since these days it's very easy to change app behaviour (by patching apks) or craft custom HTTP request (postman) , server check is a must in case of payments.
So my question is how can I verify from the token the actual amount user paid
ie. reverse convert stripeToken => actual paid amount
Update:
This is what I am looking in case of Stripe
https://developer.paypal.com/docs/integration/mobile/verify-mobile-payment/

Credit Card processing using Pin Payments - pin.net.au - using omnipay gateway, card_token method (pin.js)

I am trying to integrate Pin.net.au CC processing into my site. I am using Omnipay library to make the calls.
To not store CC details in my server, I am using the Pin.js token method.
On form submit page (after user fills in personal and CC details) javascript does a 'prevent default' and sends the data from forms (browser) straight to pin.net.au servers. Server sends a card_token in response and resubmits the form to my server.
This token is recieved successfully and I can output it in my tests.
I get into trouble when I take that token and send a purchase request to pin.net.au. According to the API docs, I need not send user and card details when I send the token (the entire point of the token, really). I send this token along with other compulsory bits like email, amount, description etc.
This works when I cURL on my terminal and I get a charge success.
However, sending this purchase/charge request using the Omnipay library, each time I get a 422 (invalid resource) that asks for the user details and CC information. It should have populated this stuff from the token I sent.
I have scoured the API docs of both Omnipay and Pin.net.au. I don't seem to be doing anything wrong. What am I missing?
Here's my charge request:
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('MY_SECRET_KEY');
$response = $gateway->purchase([
'email' => 'user#email.com',
'description' => 'Package',
'amount' => '99',
'currency' => 'AUD',
'card_token' => Input::get('card_token'),
'ip_address' => Input::get('ip_address')
])->send();
Finally, it shouldn't really matter but if you'd like to know, I'm using Laravel 4.
Your example request has an amount of 99, the minimum amount for a Pin Payments charge is $1 (amount = 100).
I don't think this is the problem you are referring to though, it looks like Omnipay does not support using the card_token gear. If you go look over here - https://github.com/adrianmacneil/omnipay/blob/master/src/Omnipay/Pin/Message/PurchaseRequest.php#L34 - you can see Omnipay isn't sending the card_token field with it's request, it only tries to send card details, which obviously aren't present from your example!
Perhaps you could get in touch with the Omnipay developers or write a pull request yourself!
This is fixed in Omnipay v1.0.4 - you should be able to use the token like this:
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('MY_SECRET_KEY');
$response = $gateway->purchase([
'description' => 'Package',
'amount' => '99.00',
'currency' => 'AUD',
'token' => Input::get('token'),
'ip_address' => Input::get('ip_address'),
'card' => ['email' => 'user#email.com'],
])->send();

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