Stripe - Create Customer and add to a plan with trial period - php

I'm able to create a customer and add it to a subscription plan; following code works:
\Stripe\Stripe::setApiKey("sk_test_tz7AKV73RPCd7p**********");
// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"plan" => $plan_id,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));
Then if I add a trial_period_days" => 30 option, I get the following error:
1 exception(s): Exception #0 (Stripe\Error\InvalidRequest): Received
unknown parameter: trial_period_days
I added it to the option hash as follow:
// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"plan" => $plan_id,
"trial_period_days" => 30,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));

OK, I got it; trial_period_days is an argument that should be used during Subscription creation, so I edited my code as follow:
// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));
// associate Customer to the Plan
\Stripe\Subscription::create(array(
"customer" => $customer,
"plan" => $plan_id,
"trial_period_days" => 30,
));

Related

2CheckOut - Error : Bad Request - Parameter error

Request Data to TwoCheckOut :
Response from TwoCheckOut.
{
"error": "Bad request - parameter error"
}
Here is the Code
$charge = Twocheckout_Charge::auth(array(
"sellerId" => '*HIDDEN*',
"merchantOrderId" => $orderID,
"token" => $token,
"currency" => $currency,
"total" => $itemPrice,
"billingAddr" => array(
"name" => $name,
"addrLine1" => $addrLine1,
"city" => $city,
"state" => $state,
"zipCode" => $zipCode,
"country" => $country,
"email" => $email,
"phoneNumber" => $phoneNumber
),
"shippingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => 'testingtester#2co.com',
"phoneNumber" => '555-555-5555'
),
"demo" => true
));
Althought i am getting unauthenticated if i send wrong 'token' key.
EDIT :
MY VIEW JS CODE
Feel free to drop your suggestions
"demo" => 'Y'
Demo key should be 'Y' not true was the issue here
TCO.loadPubKey('production');
loadPubKey should be 'production' it should not be empty

Trying to add "idempotency_key" to stripe payment intent. Not showing up in the array after submitting to stripe. Is there something wrong?

The request is successfully sent, but when I check the content of the request, the indempotency value is not in the array, Do I have a syntax error or am I doing something wrong?
$idempotency_key = bin2hex(random_bytes(16));
$intent = \Stripe\PaymentIntent::create([
'amount' => $price,
'currency' => 'usd',
'customer' => ''.$_SESSION['uid'].'',
'payment_method' => ''.$payid.'',
'description' => ''.$title.'',
"metadata" => [
'task' => ''.$_POST['pid'].'',
'offer' => ''.$_POST['accept'].'',
'category' => ''.$category.'',
'location' => ''.$location.''
],
'off_session' => false,
'confirm' => true,
'confirmation_method' => 'automatic',
'use_stripe_sdk' => true,
], [
"idempotency_key" => ''.$idempotency_key.'',
]);

php mollie payments recurring billing

My code is :
$customer = $mollie->customers->create([
"name" => $name,
"email" => $email,
]);
$customer->createSubscription([
"amount" => [
"currency" => 'USD',
"value" => 20.00,
],
"interval" => '2months',
"times" => 3,
"description" => $someDescription,
"webhookUrl" => $webhook,
"method" => NULL,
]);
$payment = $customer->createPayment([
"amount" => [
"currency" => 'USD',
"value" => 20.00,
],
"description" => $someDescription,
"redirectUrl" => $siteUrl,
"webhookUrl" => $webhook,
"metadata" => [
"order_id" => $orderId,
],
"sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
]);
The result is:
Fatal error: Uncaught exception 'Mollie\Api\Exceptions\ApiException'
with message 'Error executing API call (422: Unprocessable Entity): No
suitable mandates found for customer. Field: customerId.
Is something that I missing??
You're missing the customer ID for the customer you created previously.
$payment = $customer->createPayment([
"customerId" => $customer->id, /* see #3 in documentation */
"amount" => [
"currency" => 'USD',
"value" => 20.00,
],
"description" => $someDescription,
"redirectUrl" => $siteUrl,
"webhookUrl" => $webhook,
"metadata" => [
"order_id" => $orderId,
],
"sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
]);
I find an answer on my own question:
In order to add a subscription for an user you must first add the payment and after that the subscription.
$customer = $mollie->customers->create([
"name" => $fullName,
"email" => $email,
]);
$payment = $customer->createPayment([
"amount" => [
"currency" => $currency,
"value" => $amount,
],
"description" => $description,
"redirectUrl" => $siteUrl,
"webhookUrl" => $webhook,
"metadata" => [
"order_id" => $orderId,
],
"sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
]);
$customer->createSubscription([
"amount" => [
"currency" => $currency,
"value" => $amount,
],
"times" => $recurringLimit,
"interval" => $interval,
"description" => $description,
"webhookUrl" => $webhook,
"method" => NULL,
]);

Stripe: Missing required param: type

I am creating a bank account using PHP stripe API.
To do that I am using following PHP code:
$createBankAcc = \Stripe\Account::create(
array(
"country" => "US",
"managed" => true,
"email" => $email_db,
"legal_entity" => array(
'address' => array(
'city' => $city,
'country' => 'US',
"line1" => $address1,
//"line2" => $address2,
"postal_code" => $zip,
"state" => $state,
),
'business_name' => '',
'business_tax_id' => '',
'dob' => array(
'day' => $day,
'month' => $month,
'year' => $year,
),
'first_name' => $fname_db,
'last_name' => $lname_db,
'personal_id_number' => $pin,
'ssn_last_4' => $ssn,
'type' => 'individual',
),
'tos_acceptance' => array(
'date' => time(),
'ip' => $_SERVER['REMOTE_ADDR']
),
'transfer_schedule' => array(
"interval" => 'weekly',
"weekly_anchor" => 'sunday'
),
'external_account' => $stripeToken,
)
);
Now, after fill up the all form data it's showing me an error message.
Error message:
Missing required param: type.
I don't understand where I missed type param?
<?php
$createBankAcc = \Stripe\Account::create(
array(
"country" => "US",
"managed" => true,
"email" => $email_db,
"legal_entity" => array(
'address' => array(
'city' => $city,
'country' => 'US',
"line1" => $address1,
//"line2" => $address2,
"postal_code" => $zip,
"state" => $state,
),
'business_name' => '',
'business_tax_id' => '',
'dob' => array(
'day' => $day,
'month' => $month,
'year' => $year,
),
'first_name' => $fname_db,
'last_name' => $lname_db,
'personal_id_number' => $pin,
'ssn_last_4' => $ssn,
),
'type' => 'individual',
'tos_acceptance' => array(
'date' => time(),
'ip' => $_SERVER['REMOTE_ADDR']
),
'transfer_schedule' => array(
"interval" => 'weekly',
"weekly_anchor" => 'sunday'
),
'external_account' => $stripeToken,
)
);
You have missed type field which is required. You have a type field in legal_entity object.
It should not be in legal_entity. It should be in root array of parameter.
Detail are here

2checkout api call for create sale

I am using 2checkout api for my website product sale. Hence I am calling 2checkout api to create sale where I can call api with total amount with a single product.It's look like flowing:
try {
$charge = Twocheckout_Charge::auth(array(
"merchantOrderId" => "123",
"token" => $_POST['token'],
"currency" => 'USD',
"total" => $first_bill['amount'],
"billingAddr" => array(
"name" => $_POST['b_name'],
"addrLine1" => $_POST['b_address'],
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => $_POST['b_country'],
"email" => $_POST['b_emaill'],
"phoneNumber" => $_POST['b_phone']
),
"shippingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'enter code hereOH',
"zipCode" => '43123',
"country" => 'USA',
"email" => 'example#2co.com',
"phoneNumber" => '555-555-5555'
)
));
if ($charge['response']['responseCode'] == 'APPROVED') {
echo $response;exit;
// echo "Thanks for your Order!";
// echo "<h3>Return Parameters:</h3>";
// echo "<pre>";
// print_r($charge);
// echo "</pre>";
}
else
{
$this->Registrationmodel->delete_account($accounts_id);
echo $charge['response']['responseCode'];
exit;
}
}
catch (Twocheckout_Error $e)
{
echo $e->getMessage();
exit;
}
}
hence when i try to set line items individual like following:
try {
$charge = Twocheckout_Charge::auth(array(
"merchantOrderId" => "123",
"token" => $_POST['token'],
"currency" => 'USD',
//"total" => $first_bill['amount'],
"billingAddr" => array(
"name" => $_POST['b_name'],
"addrLine1" => $_POST['b_address'],
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => $_POST['b_country'],
"email" => $_POST['b_emaill'],
"phoneNumber" => $_POST['b_phone']
),
"LineItem" => array(
"duration" => 'Forever',
"price" => '10',
"productId" =>'1235',
"quantity" => '1',
"recurrence" => '1 Month',
"tangible" => 'N',
"type"=>'product'
),
"shippingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => 'example#2co.com',
"phoneNumber" => '555-555-5555'
)
));
if ($charge['response']['responseCode'] == 'APPROVED') {
$response = $this->return_information($charge['response']['orderNumber']);
echo $response;exit;
// echo "Thanks for your Order!";
// echo "<h3>Return Parameters:</h3>";
// echo "<pre>";
// print_r($charge);
// echo "</pre>";
}
else
{
$this->Registrationmodel->delete_account($accounts_id);
echo $charge['response']['responseCode'];
exit;
}
}
catch (Twocheckout_Error $e)
{
$this->Registrationmodel->delete_account($accounts_id);
echo $e->getMessage();
exit;
}
}
It is giving me parameter error. Please can anyone help ? how to set line items using api call?
Your lineitem array is missing the 'name' param, which is a required parameter. A full list of required params can be located here .
Also your shipping array is unnecessary as your product is intangible, therefore you could remove the shipping array.
Here's a working example I use:
try {
$charge = Twocheckout_Charge::auth(array(
"sellerId" => "xxxxxxxxx",
"li_0_merchant_order_id" => "1",
"type" => "product",
"token" => $_POST['token'],
"currency" => "USD",
// "total" => "1.00", //Only use when lineitems are not passed in
"lineItems" => array(
"0" => array(
"name" => $_POST['name'],
"price" => $_POST['price'],
"quantity" => $_POST['quantity'],
"startupFee" => $_POST['startupFee'],
"tangible" => $_POST['tangible']
)
),
"billingAddr" => array(
"name" => $_POST['customer'],
"addrLine1" => $_POST['addrLine1'],
"city" => $_POST['city'],
"state" => $_POST['state'],
"zipCode" => $_POST['zipCode'],
"country" => $_POST['country'],
"email" => $_POST['email'],
"phoneNumber" => ''
)
));
if ($charge['response']['responseCode'] == 'APPROVED') {
To better fit your app, add the "duration" & "recurrence" keys & their respective values to the lineItem array in the code I provided above. The example I provided contains all required parameters for a non-tangible sale.

Categories