how to include a parameter in strip payment gateway - php

this is my code now i want to include plan=>monthly for recurring payment but its not taking plan=>monthly parameter and giving the error UNVALID REQ any other idea about recurring payment or please correct this one. Please
try{
require_once(APPPATH.'libraries/Stripe/lib/Stripe.php');
Stripe::setApiKey("dfsdfsdfsd");
$charge = Stripe_Charge::create(array(
"amount" =>$amt,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "asdasdad"
));

You've to use 'interval' parameter.
'interval' => 'month'

Related

Stripe Charge after service complete

I am creating project using angular and larval. In my project i am integrating stripe for payment.My requirements are:
User fill their card details but not charged.User is charged after technician completes their service.I don't know how this flow will work.I already setup stripe in my project:
$charge = Stripe\Charge::create ([
"amount" => 10000,
"currency" => "gbp",
"source" => $token,
"description" => "payment",
"receipt_email"=>$email
]);
$charge = Stripe\Charge::create ([
"amount" => 10000,
"currency" => "gbp",
"source" => $token,
"description" => "payment",
"receipt_email"=>$email,
**"capture" => false**
]);
Notice the capture => false option here. This is what you need.
You will have to store the charge id some which you will find in your $charge variable.
When you want to charge actually charge do this,
$charge = \Stripe\Charge::retrieve($stripe_charge_id);
$charge->capture();
$stripe_charge_id will be the charge id that you stored earlier.
Also keep in mind that the uncaptured charge expires in 7 days.
you should check the documentation https://stripe.com/docs/api/charges/capture

I'm using Stripe API in my code and I have an error : You cannot use a Stripe token more than once: tok_1EIw1gKIAV9zC39qQnFXKzi6

I got an error saying :
Customer cus_EmVoBWWrqnWw4W does not have a linked source with ID tok_1EIw1gKIAV9zC39qQnFXKzi6.
here is my code :
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$user = new User();
$email = $user->getEmail();
//creation du client
$customer = \Stripe\Customer::create(array(
"email" => $email,
));
$charge = \Stripe\Charge::create(array(
"amount" => 2000,
"currency" => "eur",
"source" => $request ->request->get('stripeToken'),
"description" => "Stripe connect - Order 36",
"customer" => $customer->id
));
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$refund = \Stripe\Refund::create([
'charge' => $charge,
'amount' => 1000,
]);
You need to save the card to the customer and then charge the customer. After that, unless the customer has multiple sources and you want to use a specific one, you won't need to pass source to Charge::create.

Get charge ID after Stripe payment and issue refund in PHP

I'm using Stripe to process my payments in PHP with the API found here https://github.com/myg0v/Simple-Bootstrap-Stripe-Payment-Form
I'm using the following code to issue payment:
$charge = Stripe_Charge::create(array("amount" => $amount,
"currency" => "$currency",
"card" => $stripetoken,
"description" => $email));
Will the following code retrive the charge_id and refund the user?
$charge_id = $charge->stripe_charge_id;
$refund = Stripe_Refund::create(array(
"charge" => "$charge_id"
));
This syntax is for old versions of Stripe's PHP library (1.x). You should make sure that you use the latest version (currently 4.4.0).
Stripe's API reference includes samples for every request and language. You can check the sample requests for:
creating a charge
creating a refund
Basically:
$charge = \Stripe\Charge::create(array(
"amount" => $amount,
"currency" => $currency,
"source" = $token,
"description" => "Charge for $email"
));
$refund = \Stripe\Refund::create(array(
"charge" => $charge->id
));

How to cancel the stripe payment and debit the money to client account

Hello I am using following code for transaction
require_once('Stripe/lib/Stripe.php');
Stripe::setApiKey("<Api key>");
$customer = Stripe_Charge::create(array(
"amount" => 1500,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "Charge for Facebook Login code."
));
echo "<pre>";print_r($customer);die;
// Charge the Customer instead of the card
$charge = Stripe_Charge::create(array(
"amount" => 1500,
"currency" => "usd",
"customer" => $customer->id)
);
echo 'Transaction Id '.$charge->id;
I have one cancel button if i click on that the payment which done by user will be revert back to client account
You'll most likely need to refund the money you charged from the card and then have the Cancel button run the charge on the customer instead.
This can be accomplished as followed:
(1) Retrieve the charge's identifier:
$charge = \Stripe\Charge::create(array(
...
));
// you can use the var_dump function to see what's inside the $charge object
// var_dump($charge);
$chargeID = $charge->id;
(2) Refund the user:
$re = \Stripe\Refund::create(array(
"charge" => $chargeID
));
(3) Charge the customer instead:
// Charge the Customer instead of the card
$charge = Stripe_Charge::create(array(
"amount" => 1500,
"currency" => "usd",
"customer" => $customer->id)
);
echo 'Transaction Id '.$charge->id;

How to send extra parameter in stripe charge.

I am integrating stripe payment gateway. i have integrated it successfully. but the problem is that i want to send exptra parameter for stripe one time and get that in response.
Now i using
Stripe_Charge::create(array(
"amount" => number_format($amount,2,".","")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom
));
I want to send extra partameter like order_id and want that from response as stripe give customer id for recurring charge.
Stripe_Charge::create(array(
"amount" => number_format($amount,2,".","")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom,
"Order_id => $order // Is there any method to send paramerte like this.
));
Thank you.
You can use the metadata attribute. See below -
Stripe_Charge::create(array(
"amount" => number_format($amount, 2, ".", "")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom,
"metadata" => array("order_id" => $order)
));
Check the documentation here
// Get Logged Customer Id using Logged User's Email
Dictionary<string, string> Extra = new Dictionary<string, string>();
Extra.Add("email", ByEmail);
StripeCustomer customer = customerService.List(new StripeCustomerListOptions() { Limit = 1, ExtraParams = Extra }).SingleOrDefault();

Categories