I want to integrate stripe payment in react native. Application's back-end is in Laravel.
This is what I came to know. We send amount, currency to the back-end that Intents Stripe payment and return a client_secret that is used in react native to send it to stripe and made payment successful.
This was the controller code as provided
Stripe::setApiKey(env('STRIPE_SECRET'));
$intent = PaymentIntent::create([
'amount' => ($request->grand_total - $request->coupon_discount) * 100,
'currency' => $request->currency
]);
$client_secret = $intent->client_secret;
but at $intent error is returned
[Error: Request failed with status code 500]
then I tried reference: https://stripe.com/docs/payments/payment-intents
\Stripe\Stripe::setApiKey('KEY_HERE');
\Stripe\PaymentIntent::create([
'amount' => 1099,
'currency' => 'usd',
'payment_method_types' => ['card'],
'confirm' => true,
]);
but the same error
Then I tried reference: https://stripe.com/docs/api/payment_intents/object
$stripe = new \Stripe\StripeClient(
'KEY_HERE'
);
$stripe->paymentIntents->create([
'amount' => 2000,
'currency' => 'usd',
'payment_method_types' => ['card'],
]);
actually I don't have knowledge about Laravel. If any one can suggest me what's wrong.
In stripe logs page post request is now successful after removing
'confirm' => true,
but still error is same 500.
Related
I have set up PayPal Sandbox to test my PayPal Express integration, but whenever I log in to the sandbox from the payment page, I get greeted by the following error message;
I am using laravel-omnipay and omnipay-paypal with the PayPal_Express gateway.
I think this is likely to be a configuration issue (or a bug..? Although I'm hoping it's not.) in PayPal, but this is the piece of code I am using to initiate the payment:
public function checkout ()
{
$cart = Cart::forSession ();
$response = Omnipay::purchase
(
[
'amount' => $cart->getPrice (),
'currency' => preferred_currency ()->name,
'description' => (string) $cart,
'returnUrl' => URL::action ('OrderController#checkoutReturn'),
'cancelUrl' => URL::action ('OrderController#checkoutCancel')
]
)->send ();
if ($response->isSuccessful ())
dd ('successful', $response);
else if ($response->isRedirect ())
return $response->getRedirectResponse ();
else
return Redirect::to ('/cart')->with ('alerts', [new Alert ('An error occurred while attempting to process your order: ' . $response->getMessage (), Alert::TYPE_ALERT)]);
}
And the omnipay.php configuration file:
return array(
'gateway' => 'PayPal_Express',
'defaults' => array(
'testMode' => true,
),
'gateways' => array(
'PayPal_Express' => array(
'username' => '<>',
'password' => '<>',
'signature' => '<>',
'landingPage' => array('billing', 'login'),
),
),
);
The username, password and signature I am using are the ones I created in the PayPal Sandbox for my account.
The sandbox account I am using to test this is a "personal"/buyer account, with funding sources and "Payment Review" disabled. The Sandbox Accounts overview on the PayPal Developer website indicates the sandbox account's status as "complete".
I'm hoping I didn't miss something obvious. I checked out some of the other answers on Stack Overflow but none of those seemed to offer a solution for this exact problem.
Contact PayPal support, as there is something wrong on their end.
I am using Laravel Omnipay and Omnipay/Stripe. I am trying to set an application fee (Stripe resource) to be collected but after I fill in card data and post to my controller I get this error:
InvalidRequestException in AbstractRequest.php line 213: The source
parameter is required
According to Omnipay/Stripe I am allowed to pass the application_fee (AbstractRequest reference) as a transactionFee but it is not working
My controller:
$payment = $request->amount;
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey($company->settings()->get('gateway_keys')['Stripe']['test_secret']);
// Send purchase request
$response = $gateway->purchase(
[
'amount' => $payment,
'currency' => 'USD',
'token' => $request->stripeToken,
'transactionFee' => 100,
'stripe_account' => $company->settings()->get('gateway_keys')['Stripe']['account_id']
//'card' => $formData
]
)->send();
How do I get it where I can charge an application fee?
I'm trying to use Mollie in Laravel, but I'm encountering problems.
This is my code (token from the Laravel/Mollie Github page):
public function payApi($amount, $email) {
$payment = Mollie::api()->payments()->create([
'amount' => $amount,
'description' => $email,
'redirectUrl' => 'http://google.com',
]);
$payment = Mollie::api()->payments()->get($payment->id);
if ($payment->isPaid()) {
echo "Payment received";
}
}
This is the error:
Mollie_API_Exception in Base.php line 353: Error executing API call (request): Unauthorized request
I guess this is because I need to set the API test-key, but I don't know how to do that in Laravel-Mollie, it is documented for standard Mollie though.
As explained in the README.md, you need to connect Mollie to Laravel Socialite first. If you intend on using Mollie Connect, update config/services.php by adding this to the array:
'mollie' => [
'client_id' => env('MOLLIE_CLIENT_ID', 'app_xxx'),
'client_secret' => env('MOLLIE_CLIENT_SECRET'),
'redirect' => env('MOLLIE_REDIRECT_URI'),
],
And add your test-key in config/mollie.php.
I followed this link.
I did what it said, but its throwing some error:
FatalErrorException in routes.php line 29:
Class 'Stripe' not found
Line 29 Stripe::setApiKey('sk_test_bDgMM85Y8hWWaRRBrulWNeng');
A few things to check...
Did you install your stripe dependency? composer require stripe/stripe-php
Did you composer dump-auto
Your tutorial link runs stripe from the Routes file. Which is in the global namespace. Are you executing this code from a Controller or from the routes file? If from a controller, then you will need to add a use statement at the top use Stripe\Stripe;
Finally, which version of the https://github.com/stripe/stripe-php package are you using? According to the readme, there is a legacy version and a new version. The new version is has an extra level of nesting and is accessed via Stripe\Stripe and Stripe\Charge:
Legacy Version
Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = Stripe_Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge;
New Version
\Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge;
Here is the thing I did and its working. Hope its work is case of your:
try {
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$customer = \Stripe\Customer::create([
'name' => 'Jenny Rosen',
'email' => 'jenyy#hotmail.co.us',
'address' => [
'line1' => '510 Townsend St',
'postal_code' => '98140',
'city' => 'San Francisco',
'state' => 'CA',
'country' => 'US',
],
]);
\Stripe\Customer::createSource(
$customer->id,
['source' => $request->stripeToken]
);
Stripe\Charge::create ([
"customer" => $customer->id,
"amount" => 100 * 100,
"currency" => "usd",
"description" => "Test payment from stripe.test." ,
]);
Session::flash('success', 'Payment successful!');
} catch (\Exception $ex) {
return $ex->getMessage().' error occured';
Session::flash('error','Payment Failed.');
}
Charge Card
First of All create your stripe account
Stripe Register Page
if you already have Stripe account good to Go
Get API key from your Stripe and Add it to your project .env
Test API Key link : https://dashboard.stripe.com/test/apikeys
Live API Key link : https://dashboard.stripe.com/apikeys
NOTE : You can use API key directly in code but it is not good for security Install stripe-php via composer`
composer require stripe/stripe-php `
IF YOU ARE USING IN API
Setup client and API In code
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
Create token for Payment
$token = $stripe->tokens->create([
'card' => [
'number' => $card_number,
'exp_month' => $exp_month,
'exp_year' => $exp_year,
'cvc' => $cvc,
],
]);
Create Charge
$charge = Stripe\Charge::create ([
"amount" => $request->amount *100,
"currency" => $request->currency,
"source" => $token->id,
"description" => 'payment with credit/debit card'
]);
SECURITY RISK:
We should create token in front-end instead of sending card details on network we should send token
Add JS stripe to your blade file
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
Creating token On front-end using javaScript
Stripe.setPublishableKey($form.data('stripe-publishable-key'));
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
About stripeResponseHandler
This response handler will be a function where Stripe will redirect after success or failure of creating token
function stripeResponseHandler(status, response) {
if (response.error) {
/* token failed to create */
} else {
var token = response['id'];
/* you can send this token to back-end [Laravel Controller] then you need to charge function on backed */
}
}
Hope it will helpful for you
Using ci merchant for CodeIgniter. How to integrate Stripe payment gateway, and how to pass in default_settings() and in purchase() method?
I have tried Google but did not find anything helpful.
Please help me.
ci-merchant is not maintained anymore. Use Omnipay instead
-> Below Code is working good for me
$this->load->library('merchant');
$this->merchant->load('stripe');
$token = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$params = array(
'token' => $token,
'amount' => 100.00,
'currency' => 'USD',
);
$response = $this->merchant->purchase($params);