I need my customers to add their credit card info, but I don't want to charge them right away. Is there any way, I can add their details to charge later when using Stripes checkout solution and just store their card token first?
I am using Laravel Cashier on the backend.
with Laravel cashier it is realy hard to do that. You have to tweak it a little bit..
But with Stripe you can create customers and charge them later with info.
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Create a Customer:
$customer = \Stripe\Customer::create([
'source' => 'tok_mastercard',
'email' => 'paying.user#example.com',
]);
// Charge the Customer instead of the card:
$charge = \Stripe\Charge::create([
'amount' => 1000,
'currency' => 'usd',
'customer' => $customer->id,
]);
// YOUR CODE: Save the customer ID and other info in a database for later.
// When it's time to charge the customer again, retrieve the customer ID.
$charge = \Stripe\Charge::create([
'amount' => 1500, // $15.00 this time
'currency' => 'usd',
'customer' => $customer_id, // Previously stored, then retrieved
]);
Hope this helps.
// Set Stripe API key
\Stripe\Stripe::setApiKey("sk_test_HGJJKJLJLKHKJHGJHGKH");
// Retrieve Customer
$customer = \Stripe\Customer::retrieve("cus_KJHKJHJKJKHKJHKJ");
// Create new card
$data = [
"type" => "card",
"card" => [
"exp_month" => "01",
"exp_year" => "20",
"number" => "4242424242424242",
"cvc" => "123",
],
];
$card = \Stripe\Source::create($data);
// Assign the created card to the customer
$customer->sources->create(["source" => $card['id']]);
Enter card details
$token=Token::create(['card'=>
[
'number'=>'4242 4242 4242 4242',
'exp_month'=>12,
'exp_year'=>2022,
'cvc'=>121
],
)];
**//Set Stripe API key**
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
$stripe=$stripe->customers->createSource(
$customer->id,
['source' => $token->id
]);
reference
https://stripe.com/docs/api/tokens/create_card
Related
when want to connect to Stripe api to payout blance of my wallet to one customer account card, i faced this prblem.
acctually my laravel codes is:
**$card_obj = $stripe->tokens->create([
'card' => [
'number' => '4000051240000005',
'exp_month' => 8,
'exp_year' => 2023,
'cvc' => '314',
'currency' => 'cad',
],
]);
$account = $stripe->accounts->create([
'type' => 'express',
'country' => 'CA',
'capabilities' => [
'card_payments' => ['requested' => true],
'transfers' => ['requested' => true],
],
'external_account' => $card_obj->id,
]);
$payout = $stripe->payouts->create([
'amount' => 1,
'currency' => 'cad',
], [
'stripe_account' => $account->id,
]);**
and the error that response returned:
enter image description here
You cannot create a Stripe connect account and immediately start creating payouts for it. If you were to retrieve that Account through the API you'd probably see that it has a number of requirements (see api ref) that are still unfulfilled and payouts_enabled (see api ref) is false.
Connect account owners are expected to provide this missing information during the onboarding process (see https://stripe.com/docs/connect/express-accounts for how to implement an onboarding flow), and once payouts_enabled becomes true on the Account you should be able to generate payouts.
I created customer and product in stripe.
I create paymentIntent, invoiceItems and invoice for this customer. How i can connect invoice and payment?
My controller:
//check user in stripe
$stripeCustomer = $this->stripe->customers->search([
'query' => "email:'$user->email'",
]);
if (isset($stripeCustomer['data']) && !count($stripeCustomer['data']) ) {
//create new user
$stripeCustomer = $this->stripe->customers->create([
'email' => $user->email,
'name' => $user->name
]);
$stripeCustomerId = $stripeCustomer->id ?: 0;
} else {
$stripeCustomerId = $stripeCustomer['data'][0]->id;
}
$invoiceItems = $this->stripe->invoiceItems->create([
'customer' => $stripeCustomerId,
'price' => $product ? $product->stripe_price_id : null,
]);
//create draft invoice
$invoice = $this->stripe->invoices->create([
'customer' => $stripeCustomerId,
]);
//create payment
$paymentIntent = $this->stripe->paymentIntents->create([
'customer' => $stripeCustomerId,
'amount' => $invoiceItems->amount,
'currency' => Payment::CURRENCY_EUR,
'payment_method_types' => ['card']
]);
$clientSecret = $paymentIntent->client_secret;
After submitting form (number card, etc...) I am confirmPayment in view:
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url: "{{route('payment-success'), [ 'token' => $token ])}}",
},
});
My paymentSuccess method:
public function paymentSuccess($token)
{
$data = json_decode(base64_decode($token));
//$data->paymentId
// maybe here i must pay invoice for my paymentId???
}
Invoices can be paid in two ways
Stripe automatically creates and then attempts to collect payment on
invoices for customers on subscriptions according to your
subscriptions settings. However, if you’d like to attempt payment on
an invoice out of the normal collection schedule or for some other
reason, you can do so as follows.
$this->stripe->invoices->finalizeInvoice(
$invoice->id,
[]
);
$this->stripe->invoices->pay(
$invoice->id,
[]
);
OR
You can manually send an invoice through email to your customer to
pay. You can do so as follow
$this->stripe->invoices->finalizeInvoice(
$invoice->id,
[]
);
$this->stripe->invoices->sendInvoice(
$invoice->id,
[]
);
I am making an app like Uber. I want to pay employees every start of week. but i don't have any idea about it. Every week the system will calculate and pay the driver's salary.
With the Bank information submitted by the customer, I transferred money from the customer to the admin, but I don't know how to pay the driver's salary.o the customer.
This my code
// account test
$bank = $stripe->tokens->create([
'bank_account' => [
'country' => 'US',
'currency' => 'usd',
'account_holder_name' => 'Jenny Rosen',
'account_holder_type' => 'individual',
'routing_number' => '110000000',
'account_number' => '000123456789',
],
]);
// create account
$account = \Stripe\Account::create(
array(
"country" => "US",
'type' => 'custom',
'capabilities' => [
'card_payments' => [
'requested' => true,
],
'transfers' => [
'requested' => true,
],
],
'external_account' => $bank->id
)
);
$re = $stripe->transfers->create([
'amount' => 400,
'currency' => 'usd',
'destination' => $account->id,
'transfer_group' => 'ORDER_95',
]);
return $re;
Error response:
"Your destination account needs to have at least one of the following capabilities enabled: transfers, legacy_payments".
How to pay employee via Stripe. Please help me !
Hello I am new to PayPal integration. I am using the Express checkout of PayPal for payment.
I wrote the code use SetExpressCheckout method then GetExpressCheckout method and then use DoExpressCheckout method. After DoExpressCheckout I am calling the CreateRecurringPaymentsProfile for recurring payment. Code as follows-
$recurringdata = array(
'TOKEN' => $token,//token id
'PayerID' => $payerid,//payer id
'PROFILESTARTDATE' => date('Y-m-d H:i:s',$time),
'DESC' => "description",
'BILLINGPERIOD' => 'Day',
'BILLINGFREQUENCY' => 1,
'AMT' =>$checkoutDetails['PAYMENTREQUEST_0_AMT'],
'TRIALBILLINGPERIOD'=>'Day',
'TRIALBILLINGFREQUENCY'=>1,
'TRIALAMT'=> 0,
'CURRENCYCODE' => 'USD',
'COUNTRYCODE' => 'US',
'MAXFAILEDPAYMENTS' =>3
);
$responserecurring = $paypal->request('CreateRecurringPaymentsProfile', $recurringdata);
This code creates the profile but I can not see that any recurring payment is done. I am not getting what actually happens. Is am I missing to pass any parameter in request.
Actually i am missing the one parameter i.e. 'TRIALTOTALBILLINGCYCLES'. This parameter is an optional so i am not used this. So my trail period goes in infinite state. So payment is not deducting from account.I pass the data like as_
$recurringdata = array(
'TOKEN' => $token,//token id
'PayerID' => $payerid,//payer id
'PROFILESTARTDATE' => date('Y-m-d H:i:s',$time),
'DESC' => "description",
'BILLINGPERIOD' => 'Day',
'BILLINGFREQUENCY' => 1,
'AMT' =>$checkoutDetails['PAYMENTREQUEST_0_AMT'],
'TRIALBILLINGPERIOD'=>'Day',
'TRIALBILLINGFREQUENCY'=>1,
'TRIALAMT'=> 0,
'TRIALTOTALBILLINGCYCLES' => 1,
'CURRENCYCODE' => 'USD',
'COUNTRYCODE' => 'US',
'MAXFAILEDPAYMENTS' =>3
);
$responserecurring = $paypal->request('CreateRecurringPaymentsProfile', $recurringdata);
I've been getting this error from omnipay bridge whenever I try to capture credit card payment:
Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.
Here's my code:
//...
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGateway('paymentexpress_pxpost', ['factory' => 'omnipay_paymentexpress_pxpost', 'username' => 'some_username', 'password'=>'some_password'])
->getPayum();
$card = [
'number' => $request->input('cc_number'),
'expiryMonth' => $request->input('expiry_month'),
'expiryYear' => $request->input('expiry_year'),
'cvv' => $request->input('cvv'),
'name' => $request->input('card_name')
];
$payment = new ArrayObject(['amount' => '1.00', 'currency' => 'AUD', 'card' => $card]);
if ($reply = $payum->getGateway('paymentexpress_pxpost')->execute(new Capture($payment), true)) {
// convert reply to http response
}
//...
The ->execute() function is the one that throws an error. I also referred to the same issue from Error: Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.
Why do you create a new payum builder instead of using the one from laravel package. The one from package have some additional stuff set (like obtain credit card action).
Accoding to the docs you should do something like this
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('paymentexpress_pxpost', [
'factory' => 'omnipay_paymentexpress_pxpost',
'username' => 'some_username',
'password'=>'some_password'
])
;
});