Hosted PHP application :: Error in Stripe Payment integration - php

I have hosted my PHP application and everything is working fine except for the Stripe Payment integration in it.
Can someone suggest what could be the error?
require_once('../../Stripe/init.php');
\Stripe\Stripe::setApiKey('sk_test_************');
$e="";
// 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
try {
$charge = \Stripe\Charge::create(array(
"amount" => $stripe_amount, // amount in cents, again
"currency" => "cad",
"source" => $token,
"description" => "Buy Gift Card"
));
} catch(\Stripe\Error\Card $e) {
$e = "Your card has been declined, please enter a valid card";
}
It's working fine on my local machine, but on my hosting it gives me this error:
500 - Internal server error. There is a problem with the resource you
are looking for, and it cannot be displayed.

Related

What is No such destination in stripe?

I am trying to transfer amount from 1 stripe account to another stripe account but I am getting this error "No such destination:".
I tried to add different client ids. But it isn't working.
\Stripe\Stripe::setApiKey('APP Key');
$transfer = \Stripe\Transfer::create([
"amount" => 400,
"currency" => "usd",
"destination" => "ca_FtG3t5**********",
"transfer_group" => "ORDER_95"
]);
return $transfer;
I want this to transfer amount to other stripe account.
"No such destination" means the account you are trying to transfer to does not exist, or is not connected to your account.
Most Stripe accounts are in the format of acct_xxxyyyzzz, the id you have here ca_xxxyyyyzz does not look like an Stripe account id. Find the accounts connected to yours here.

Stripe charge card get fatal error with php rest api

I am using stripe charge card api for card payment. Token successfully created and this information goes to stripe server also. But when go for charge payment it give fatal error.
I am using amazone ubuntu instance for publish my website.
My php code is :-
$token=$this->input->post('stripeToken');
var_dump($token);
\Stripe\Stripe::setApiKey("xxx");
// 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
try {
$charge = \Stripe\Charge::create(array(
"amount" => 100, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "Example charge"
));
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
It give fatal error.
Fatal error: Uncaught exception 'Stripe\Error\ApiConnection' with message 'Could not connect to Stripe
(https://api.stripe.com/v1/charges). Please check your internet
connection and try again. If this problem persists, you should check
Stripe's service status at https://twitter.com/stripestatus, or let us
know at support#stripe.com. (Network error [errno 28]: Connection
timed out after 30055 milliseconds)' in
/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php:216
Stack trace: #0
/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php(178):
Stripe\HttpClient\CurlClient->handleCurlError('https://api.str...',
28, 'Connection time...') #1
/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/ApiRequestor.php(184):
Stripe\HttpClient\CurlClient->request('post', 'https://api.str...',
Array, Array, false) #2
/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/ApiRequestor.php(59):
Stripe\ApiRequestor->_requestRaw('post', '/v1/charges', Array, Ar in
/opt/lampp/htdocs/devbeacon/application/libraries/stripe/lib/HttpClient/CurlClient.php
on line 216
I don't know the reason behind that.
The message shows Network error [errno 28], which is a curl error, defined as a CURLE_OPERATION_TIMEDOUT error. This is a connection error.
Connection errors are usually due to security group settings and not allowing outbound https, in this case to the API endpoint (https://api.stripe.com/v1/charges).
Can you try to curl https://api.stripe.com/v1/charges and confirm you can connect?
You should get the following:
{
"error": {
"type": "invalid_request_error",
"message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/d
ocs/api#authentication for details, or we can help at https://support.stripe.com/."
}
}
If you do not get that response the command line on your server, then your code will not be able to connect either. Review your outgoing security group settings, and allow outbound HTTPS to the IP of the endpoint, or 0.0.0.0/0.

Stripe payment issue with "application fee"

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

Integrating PayPal REST API into Laravel using Omnipay - The card parameter is required

I'm using L5 and want to integrate my PayPal purchases into that system. The sandbox is already set up and I can do all my payments using the real PayPal API package, but as I want to try to do it with Omnipay I'm struggling a bit:
When I execute this code:
Route::get('test', function()
{
$gateway = Omnipay::create('PayPal_Rest');
$gateway->setClientId('{my id}');
$gateway->setSecret('{my secret}');
$gateway->setTestMode(true);
$params = array(
'cancelUrl' => 'http://webshop.app',
'returnUrl' => 'http://webshop.app/testresp',
'name' => 'Your Purchase',
'description' => 'Your Description',
'amount' => '15.99',
'currency' => 'EUR'
);
Session::put('params', $params);
Session::save();
$resp = $gateway->purchase($params)->send();
if ($resp->isSuccessful()) {
// payment was successful: update database
print_r($resp);
} elseif ($resp->isRedirect()) {
// redirect to offsite payment gateway
$resp->redirect();
} else {
// payment failed: display message to customer echo
$resp->getMessage();
}
});
I get this:
InvalidRequestException in AbstractRequest.php line 122:
The card parameter is required
Seems like I would have to initiate that purchase with credit card information of the client, which I do not want to gather (hence using PayPal in the first place). Is there any way to use that API without usage of a credit card?
I don't like the usage of the Express API as I don't want my PayPal username and password within my code. For several reasons.
The Card array field is required. it's not required to insert credit card number, but you will need to provide some information.
From the official docs:
Even off-site gateways make use of the CreditCard object, because often you need to pass customer billing or shipping details through to the gateway.
Check out the following branch of my fork of the omnipay-paypal gateway code: https://github.com/delatbabel/omnipay-paypal/tree/accept-paypal-payments
That includes code that allows you not to pass through a credit card and have PayPal do the payment processing.
I have submitted a PR but it hasn't been merged into the main omnipay-paypal repository yet.

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