Using Stripe's PHP API I was able to create a bi-weekly subscription for my customers but I'm having an issue, the "description" on all subscriptions is defaulting to "Subscription creation" and I can't seem to find a way to add a description although I thought the following code worked in the past (I updated the API since then). Please see my code below
case "BiWeekly":
try {
$product = \Stripe\Product::create([
"name" => "NEO Bi-Weekly Payments for $cname",
"type" => "service",
"statement_descriptor" => "NEO",
]);
$plan = \Stripe\Plan::create([
"product" => $product->id,
"amount" => $totalAmount,
"currency" => "usd",
"interval" => "week",
"interval_count" => 2,
"usage_type" => "licensed",
]);
$subscription = \Stripe\Subscription::create([
"customer" => $customer->id,
"items" => [["plan" => $plan->id]],
"metadata" => array("Name" => $cname, "For" => "NEO Bi-Wkly Pymts")
]);
} catch(\Stripe\Error\Card $e) {
$body = $e->getJsonBody();
$err = $body['error'];
header("Location: https://www.neo.com/declined/");
exit();
};
break;
Any help would be greatly appreciated!
As clarified in the comments - description='Subscription creation' is on the corresponding PaymentIntent (not the Subscription).
There's no easy way to do this - it's not possible to specify a description when creating the Subscription to automatically populate on the corresponding PaymentIntent.
What I suggest is to :
Create the Subscription with metadata
listen for the invoice.payment_succeeded webhook event - https://stripe.com/docs/webhooks
The invoice.payment_succeeded will contain the metadata from step 1 in lines and the payment_intent
Example
...
"lines": {
"object": "list",
"data": [
{
"id": "il_...",
"object": "line_item",
...
"metadata": {
"subscription_metadata": "some_value"
},
...
"payment_intent": "pi_...",
...
using the data from step 3, make a request to update the PaymentIntent's description
On a side note, you should no longer be creating Plans (which is deprecated), but should be creating Prices instead.
Related
Is there any way to send customer id along with stripe information to the stripe dashboard? I don't know how to do this or this is required if I want to save the payment methods for every customer in my database
I found in stripe dashboard that the customer is none, please see this: https://imgur.com/uNTeEfb
here stripe jquery:
if (!$form.data('cc-on-file')) {
e.preventDefault();
stripe.createToken(number).then({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
}
Stripe controller
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
Stripe\Charge::create ([
"amount" => $total*100,
"currency" => "usd",
"source" => "tok_visa"
]);
You can can send addition paramaters as array using metadata keyword
in stripe,
Like the below code
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
Stripe\Charge::create ([
"amount" => $total*100,
"currency" => "usd",
"source" => "tok_visa",
"metadata" => array("cus_id" => $cus_id, "name" => $user_name)
]);
I followed the API reference here but when I try to create and invoice, I get this error:
missing an item
So I created some items and now I want to add an item to the invoice but I don't understand how to write it in the invoice array.
Right now I have this code. It creates the invoice but with ALL the items I created until now. How do I specify the item within the function?
try {
require_once('./Stripe/init.php');
\Stripe\Stripe::setApiKey("sk_test_iP2aEsMDAc0ZCh5XGdE6AOnt");
$customer = \Stripe\Invoice::create(array(
"customer" => "cus_CML6eYLJif4EJ5",
"billing" => "charge_automatically",
"description" => "Testing invoices"
));
echo 'Invoice created';
}
More info
\Stripe\Stripe::setApiKey("sk_test_iP2aEsMDAc0ZCh5XGdE6AOnt");
\Stripe\InvoiceItem::create(array(
"customer" => "cus_CML6eYLJif4EJ5",
"amount" => 2500,
"currency" => "usd",
"description" => "One-time setup fee")
);
I'm using Stripe for my recurring payment for my SAAS.
The problem I'm facing today is : I would like to offer to my client the choice to upgrade or downgrade their subscription to my service.
So the code I have actually is the following (according to the doc here):
\Stripe\Subscription::update($subscriptionID, [
'items' => [
'id' => $itemID,
'plan' => $planId
]
]);
The $subscriptionID, $itemID and $planId return my the right value I need but no update on the Stripe side.
I have just this error:
{
"error": {
"type": "invalid_request_error",
"message": "Invalid array",
"param": "items"
}
}
Any help on his please ?
Thanks.
You just need to cover items in one more array level, like so:
\Stripe\Subscription::update($subscriptionID, [
'items' => [
[
'id' => $itemID,
'plan' => $planId
]
]
]);
It was working using this code:
$customer = \Stripe\Customer::retrieve($CustomerId);
$subscription = $customer->subscriptions->retrieve($subscriptionID);
$customer->updateSubscription(['plan' => $planId]);
$customer->save();
Strange that the Stripe API do not talk about this solution.
i was having a problem with Wepay API. My codes are correct but it keeps on returning an error saying "payment method does not exist or does not belong to app". I already configured the permission to allow tokenized credit cards. But still. Any feedback is greatly appreciated. Thanks!
Here is my code
require_once('public/payment/wepay/wepay.php');
$user = API::get_client(['fldClientEmail' => $email])->first();
// change to useProduction for live environments
\Wepay::useStaging(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET);
$wepay = new \WePay($user->fldClientWepayTokenAccess);
// $wepay = new \WePay(WEPAY_ACCESS_TOKEN);
// dd($email);die;
// dd($user->fldClientWepayAccountID);die;
// charge the credit card
$response = $wepay->request('checkout/create', [
'account_id' => $user->fldClientWepayAccountID,
'amount' => number_format(Input::get('amount_tipped'),2),
'currency' => 'USD',
'short_description' => 'A short description',
'type' => 'goods',
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => Input::get('cc_id')
)
)
]);
// display the response
return $response;
Make sure that when you follow the tutorial from their docs, you replace all of the credentials from the examples. I was using their Javascript library for the tokenization of the credit card with the client_id they provided.
response = WePay.credit_card.create({
"client_id": YOUR.CLIENT.ID.HERE,
"user_name": valueById('name'),
"email": valueById('email'),
"cc_number": valueById('cc-number'),
"cvv": valueById('cc-cvv'),
"expiration_month": valueById('cc-month'),
"expiration_year": valueById('cc-year'),
"address": {
"postal_code": valueById('postal_code')
}
If you don't provide your own, is like you were creating those credit cards for another application that's not yours.
If this didn't do the trick, check this article, hopefully it does:
https://support.wepay.com/hc/en-us/articles/203609273-WePay-API-Error-Codes
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.""
));