HI I am using braintree(braintree/braintree_php": "4.5.0) . I have implemented the 3dsecure in the web.It working fine. I need to auto renew the payment with paymentMethodToken. Below code i have used for auto renewal.
$trans = [
'amount' => "14.63",
'merchantAccountId' => "Vo**ID",
'paymentMethodToken' =>"token",
'transactionSource' => "recurring",
'customFields' => [
'client_id' => "id",
'service_id' => "id",
'invoice_id' => "id",
'action' => "autorenew",
'slots' => "15",
],
'options' => [
'submitForSettlement' => true,
'storeInVaultOnSuccess' => true,
'paypal' => [
'description' =>"Renew server",
]
]
];
$transaction = $gateway->transaction()->sale($trans);
When run this code i get below error
Authorization in Util.php line 59:
The above code is working when the user enter the credit card information to pay.This only gives error when i do payment with paymentMethodToken to auto renew the payments.Any help?
reference : https://developers.braintreepayments.com/guides/paypal/server-side/php
As per I understood your requirement. You need to do auto payment.
For that, Braintree provide the best way to do this called Subscription.
Let me know, If you need any more help.
Related
I am developing a wordpress website for a client.
He needs different types of packages. For most of these packages I developed a simple Stripe checkout webpage, using its documentation.
The problem is that I need this workflow:
first month x dollars
second month x dollars
after one year subscription y dollars
I've already done this using Subscription Schedule. But it needs a customer ofc. How can I charge before and after charging create this Subscription Schedule? I don't know how to deal with this, how to charge using Stripe checkout simple already built page or do I need to create one by myself, where user needs to add his card, pay, and get the customer_id?
function checkout3() {
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('sk_test_51e7DRPLRnISGb5vSFxnvvuDx1GzhlBIFeazcmpEevsUFf29jHXJ1YgE2xaJ1lGfzjtKzE8uoN0eR9Klaq00CnMFWvfB');
// The price ID passed from the front end.
// $priceId = $_POST['priceId'];
$priceId = 'price_1LPahmIne7DRPLRnFXV6Uz34';
$futureDate= strtotime(date('Y-m-d', strtotime('+1 year')));
$customer = \Stripe\Customer::create(
[
'description' => 'My First Test Customer (created for API docs at https://www.stripe.com/docs/api)',
]
);
$session = \Stripe\SubscriptionSchedule::create([
'customer' => $customer["id"],
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => 'price_1LRF5CIne7DRPLRnwuLVE2pu',
'quantity' => 1,
],
],
//'end_date' => $futureDate,
'iterations' => 1,
],
[
'items' => [
[
'price' => 'price_1LRF5cIne7DRPLRngevvIZiw',
'quantity' => 1,
],
],
'iterations' => 1,
],
[
'items' => [
[
'price' => 'price_1LPujQIne7DRPLRnj3EOweJN',
'quantity' => 1,
],
],
],
],
]);
// Redirect to the URL returned on the Checkout Session.
// With vanilla PHP, you can redirect with:
//header("HTTP/1.1 303 See Other");
//header("Location: " . '$session->url');
}
So right now, the subscription schedule is added to the Stripe dashboard, the page it's keep loading infinitely, but without charging... How to deal with this?
public static function firebase_checkout3_func() {
$html = "";
$html .= "<form id='firebase-checkout' action='/wp-json/api/checkout2' method='POST'>
<button type='submit' id='checkout-button'>Începe acum</button>
</form>";
return $html;
}
Use Stripe hosted Checkout Page with setup mode to collect
a Customer's SetupIntent
Retrieve the Payment Method inside the SetupIntent
Set it as the customer's invoice_settings.default_payment_method
Create a Subscription Schedule with that Customer Id as normal
okay, this is my first time to ask a question here so please give grace if it's not very clear. Anyway, I have this code in Laravel Billing.php.
Is this correct? Whenever a new customer is created, it doesn't have it's user email address but instead this unknown#domain.com was assigned to the user.
This was set by my previous developer. But ever since we hired him for just simple fix, we've had numerous issues with the site.
$stripeCustomer = StripeCustomer::create([
'email' => $currentCustomer->email ? $currentCustomer->email : 'unknown#domain.com',
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'card_owner_email' => $currentCustomer->email ? $currentCustomer->email : false,
'company_name' => $company->name,
],
]);
You can remove customer email from the StripeCustomer when creating since stripe API said that email field of customer is optional. Here is the reference link
Here what you should fix:
$customerObject = [
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'company_name' => $company->name,
],
];
if ($currentCustomer->email) {
$customerMetadata["metadata"]["card_owner_email"] = $currentCustomer->email;
$customerObject["email"] = $currentCustomer->email;
}
$stripeCustomer = StripeCustomer::create($customerObject);
I'm trying to create a subscription for the merchant's users but facing "You can not pass payment_intent_data in subscription mode" error. With regular payments, it works well, but subscriptions aren't working.
Here is an example of what I want to do: John has an e-commerce shop based on recurring billing. Matthew is John's customer and wants to purchase a subscription from John. How can I easily take fees and transfer money to John's connect account while using "Stripe Checkout"?
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price' => $priceIntent->id,
'quantity' => 1,
]],
'customer' => Auth::User() -> stripe_code,
'mode' => 'subscription',
'payment_intent_data' => [
'application_fee_amount' => $total_fees,
'transfer_data' => [
'destination' => $merchantId,
],
],
'success_url' => env('APP_URL') . '/order/success/{CHECKOUT_SESSION_ID}',
'cancel_url' => env('APP_URL') . '/order/cancel/',
]);
Thanks!
Basically, you can't use payment_intent_data on a Checkout Session in subscription mode, since the subscription creates invoices instead of PaymentIntents.
To do this, you need to use the subscription_data hash: https://stripe.com/docs/api/checkout/sessions/create?lang=php#create_checkout_session-subscription_data-application_fee_percent and specify the merchant account.
Example of the API call with merchant details:
$session = \Stripe\Checkout\Session::create([
'subscription_data' => [
'application_fee_percent' => $fees_percent,
],
],array("stripe_account" => "acct_xxxxxxxxx"));
Also, don't forget to pass all the other required variables in the call.
Cheers :)
Using the code sample from here, I wish to add payment with Vipps to the payment options, so I added the following key-values as per the documentation to the request:
$request['paymentwindow'] = [
'paymentmethods' => [
[
'id' => 'paymentcard',
'action' => 'include'
],
[
'id' => 'vipps',
'action' => 'include'
]
]
];
But, this seems to have no effect and no option for payment with Vipps is added to the payment window. What am I doing wrong?
Short answer: Vipps is only available in production account
I know that asking this here could be throwing a stone in the dark because I found 2 other similar questions but none had any answers to it.
Any way, I hope someone has already found the solution for this and can shed a light on it.
Let me explain the scenario first as it might help with finding a solution:
I am creating stripe custom connect accounts like this:
$acct = \Stripe\Account::create(array(
"country" => "US",
"type" => "custom",
"email" => "email#mail.com"
));
Then I add Bank Accounts to them like so:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "bank_account",
"country" => "US",
"currency" => "usd",
"account_holder_name" => 'Jane Austen',
"account_holder_type" => 'individual',
"routing_number" => "111000025",
"account_number" => "000123456789"
)
));
This all works fine so far....
Now, what I need to do is to be able to transfer Money/Payments from the connected custom accounts into their Bank accounts.
For that purpose, I will need to add a Credit Card to that connetced account so that card details can be used for making payments into the Bank Accounts.
So I went ahead and tried this:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
And that did NOT work and gave me this error:
Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.
So I changed my strategy and tried this:
$result = \Stripe\Token::create(
array(
"card" => array(
"name" => "Some Name",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
$token = $result['id'];
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"source" => "".$token.""
)
));
However, this gave me the same error message!!!
This is very frustrating because if you look at their own API documentation, you will clearly see that they say:
source required
Either a token, like the ones returned by Stripe.js, or a dictionary containing a user's credit card details (with the options shown below). Stripe will automatically validate the card.
This can be seen here:
https://stripe.com/docs/api#create_card
Could someone please advice on this issue?
I cannot use stripe.js in my project so I will need to use the API.
Any help would be greatly appreciated.
Thanks in advance.
First Edit:
Here is a strange one.. I generated a Stripe card token from here:
https://codepen.io/fmartingr/pen/pGfhy
Note that the above codepen uses the stripe.js to generate the tokens....
and tried to use the token from there in my PHP code like so:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"source" => "tok_1AqPXeDQzcw33c71uncYBFdm"
)
));
but this gives me the exact same error:
Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.
Please use this it will add your external account
$result = \Stripe\Token::create(
array(
"card" => array(
"name" => "Some Name",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
$token = $result['id'];
$account->external_accounts->create(
array(
'external_account' => "".$token.""
));