Plan already exists - stripe/php - php

I would like to conclude a monthly plan created by myself with the customer's ID and complete the fixed amount payment.
However, when creating a "Subscription" after creating the original plan, "Plan already exists" is output.
I can not truly understand the above error. For example, if I create and run "Subscription" without creating original plan, the code will work correctly.
The log at that time is below. However, with this, it is impossible to judge what kind of plan contents are adapted to customers. How can you associate your plan with "Subscription"?
Implement Subscription without creating a plan
// echo $customer->id;
// $my_original_plan = \Stripe\Plan::create(array(
// "id" => "basic-monthly",
// "interval" => "month",
// "currency" => "jpy",
// "product" => array("name" => "aaaaaa"),
// "amount" => 9800
// ));
// echo $my_original_plan;
$subscription = \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
array(
"plan" => "basic-monthly",
),
)
));
echo $subscription;
The above log
Stripe\Subscription JSON: {
"id": "sub_CXKozer939U80A",
"object": "subscription",
"application_fee_percent": null,
"billing": "charge_automatically",
"billing_cycle_anchor": 1521674075,
"cancel_at_period_end": false,
"canceled_at": null,
"created": 1521674075,
"current_period_end": 1524352475,
"current_period_start": 1521674075,
"customer": "cus_CXKovj687dz1Po",
"days_until_due": null,
"discount": null,
"ended_at": null,
"items": {
"object": "list",
"data": [
{
"id": "si_CXKoBTbLbBICEL",
"object": "subscription_item",
"created": 1521674075,
"metadata": [],
"plan": {
...
Plan already exists
// echo $customer->id;
$my_original_plan = \Stripe\Plan::create(array(
"id" => "basic-monthly",
"interval" => "month",
"currency" => "jpy",
"product" => array("name" => "aaaaaa"),
"amount" => 9800
));
// echo $my_original_plan;
$subscription = \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
array(
"plan" => "basic-monthly",
),
)
));
echo $subscription;
All source code
<?php
header("Content-type: text/plain; charset=UTF-8");
if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
if (isset($_POST['request']))
{
//make token from ajax js
$token_from_js = $_POST['request'];
//stripe from composer
require_once 'vendor/autoload.php';
//set api key
\Stripe\Stripe::setApiKey("sk_test_");
//make customer info
$customer = \Stripe\Customer::create(array(
"description" => "taylor#example.com",
"source" => "$token_from_js",
));
// echo $customer->id;
$my_original_plan = \Stripe\Plan::create(array(
"id" => "basic-monthly",
"interval" => "month",
"currency" => "jpy",
"product" => array("name" => "aaaaaa"),
"amount" => 9800
));
// echo $my_original_plan;
$subscription = \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
array(
"plan" => "basic-monthly",
),
)
));
echo $subscription;
};
};
?>

\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
$product = \Stripe\Product::create([
'name' => 'My SaaS Platform',
'type' => 'service',
]);
$plan = \Stripe\Plan::create([
'currency' => 'usd',
'interval' => 'month',
'product' => $product->id,
'nickname' => 'Pro Plan',
'amount' => 3000,
]);
You should try to use product_id instead of an array.

Related

how to create Product Catalog Batch , ecommerce on facebook business sdk php

i use facebook business sdk 11.0
for create new product category ecommerce
https://github.com/facebook/facebook-php-business-sdk
I tried to read document but I still can't understand it.
try but show error
(#100) The parameter requests is required
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'retailer_id' => 'retailer-6',
"availability" => "in stock",
"brand" => "Nike",
"category" => "t-shirts",
"description" => "product description",
"image_url" => "http://www.images.example.com/t-shirts/1.png",
"name" => "product name",
"price" => "10.00",
"currency" => "USD",
"condition" => "new",
"url" => "http://www.images.example.com/t-shirts/1.png",
"retailer_product_group_id" => "product-group-1"
);
echo json_encode((new ProductCatalog($id))->createBatch(
$fields,
$params
)->exportAllData(), JSON_PRETTY_PRINT);
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$data[] = array(
'method'=>'CREATE',
'retailer_id'=>'retailer-6',
'data'=>array(
"availability" => "in stock",
"brand" => "Nike",
"category" => "t-shirts",
"description" => "product description",
"image_url" => "http://www.images.example.com/t-shirts/1.png",
"name" => "product name",
"price" => "1000", //it will be 1000 otherwise it will through error
"currency" => "INR",
"condition" => "new",
"url" => "http://www.images.example.com/t-shirts/1.png",
"retailer_product_group_id" => "product-group-1"
)
);
$params = array(
'access_token'=>$access_token,
'requests'=>$data
);
echo json_encode((new ProductCatalog($product_catalog_id))->createBatch(
$fields,
$params
)->exportAllData(), JSON_PRETTY_PRINT);
Try this one it will work.

PayPal Orders API schema

I am setting up a payment integration with PayPal Checkout Buttons and Paypal Orders API V2. Payments are going throw, but now I want to include items in my Order request, but I getting:
As PayPal docs say I have to pass array (contains the item object) Link to Orders API purchase_unit object Link to Orders API item object. But I'm still getting this error.
This is my request:
public function createOrder($value, $order, $products, $currency = 'EUR')
{
return $this->makeRequest(
'POST',
'/v2/checkout/orders',
[],
[
'intent' => 'CAPTURE',
'payer' => [
'name' => [
'given_name' => $order->billing_firstname,
'surname' => $order->billing_lastname
],
'email_address' => $order->email_address,
'address' => [
'address_line_1' => $order->billing_street_address,
'admin_area_2' => $order->billing_city,
'postal_code' => $order->billing_postcode,
'country_code' => $order->billing_country_code
],
],
'purchase_units' => [
0 => [
'amount' => [
'currency_code' => $currency,
'value' => $value,
],
'description' => 'Order: ' . $order->order_serial_number,
'items' => [
0 => [
'name' => 'Item1',
'unit_amount' => 100,
'quantity' => 1
],
],
],
],
'application_context' => [
'brand_name' => config('app.name'),
'shipping_preference' => 'NO_SHIPPING',
'user_action' => 'PAY_NOW',
'return_url' => route('approval.paypal', $order->id_order),
'cancel_url' => route('payment.cancelled', $order->id_order),
]
],
[],
$isJsonRequest = true
);
}
I'm using: Laravel and Guzzle/HTTP to perform payment requests.
As I say, payments are going throw, but when I try to add Items to Order, I'm getting this error.
You haven't posted the full (rest of the) error response that details the problem, so there may be another issue we can't see, but one thing that's missing is the amount.breakdown.item_total subtotal, which is required when passing an items array with amounts: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
A simple example in the API's JSON format, which you can adapt to PHP array syntax:
// based on example array from https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
"purchase_units": [{
"amount": {
"value": "17.49",
"currency_code": "USD",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "17.49"
},
}
},
"items": [
{
"unit_amount": {
"currency_code": "USD",
"value": "17.49"
},
"quantity": "1",
"name": "item 1",
},
],
}
]

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,
]);

Magento SOAP order failes with message "birthday is required"

I use this code to create an order through the magento (1.9) soap api v2.
The problem is, that I have to do this for a site, where the dob (day of birth) is a required field. Therefor I do get an error message - on that site - "birthday is required".
Do anybody know how to solve that problem (without disabling the dob as required field)?
$storeId = '1';
$quoteId = $client->shoppingCartCreate($session,$storeId);
echo "<br>Quote ID : " . $quoteId;
/* Set cart customer */
$guest = true;
if ($guest)
{
$customerData = array(
"firstname" => "testFirstname",
"lastname" => "testLastName",
"email" => "testEmail#mail.com",
"mode" => "guest",
"website_id" => "1"
);
}
else
{
$customer = array(
"customer_id" => '69301',
"website_id" => "1",
"group_id" => "1",
"store_id" => "1",
"mode" => "customer",
);
}
//Set cart customer (assign customer to quote)
$resultCustomerSet = $client->shoppingCartCustomerSet($session, $quoteId, $customerData,$storeId);
echo "<br>Set Customer: ";
var_dump($resultCustomerSet); //Set customer
/* Set customer addresses Shipping and Billing */
$addresses = array(
array(
"mode" => "shipping",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
),
array(
"mode" => "billing",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
)
);
//Set cart customer address
$resultCustomerAddress = $client->shoppingCartCustomerAddresses($session, $quoteId, $addresses,$storeId);
echo "<br>Set Customer Address: ";
var_dump($resultCustomerAddress); //Set customer addresses
/* Add products to cart */
$product = array(
'product_id' => '905',
// 'sku' => 'simple_product',
'qty' => '1',
'options' => null,
'bundle_option' => null,
'bundle_option_qty' => null,
'links' => null);
$product2 = array(
'product_id' => '904',
// 'sku' => 'simple_product',
'qty' => '2',
'options' => null,
'bundle_option' => null,
'bundle_option_qty' => null,
'links' => null);
$addToCart = $client->shoppingCartProductAdd($session, $quoteId, array($product,$product2),$storeId);
echo "<br>Add to Cart: ";
var_dump($addToCart);
/* Set payment method */
$responsePayment = $client->shoppingCartPaymentMethod($session, $quoteId, array(
'method' => 'cashondelivery',
),$storeId);
echo "<br>Set Payment method: ";
var_dump($responsePayment);
/* Set shipping method */
$setShipping = $client->shoppingCartShippingMethod($session, $quoteId, 'flatrate_flatrate',$storeId);
echo "<br>Set Shipping method: ";
var_dump($setShipping);
/* Set Discount Code */
try
{
$result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
echo "<br>Apply discount code: ";
var_dump($result);
}
catch(Exception $ex)
{
echo "<br>Discount code Failed: " . $ex->getMessage();
die();
}
$orderId = $client->shoppingCartOrder($session, $quoteId, $storeId, null);
echo "<br>Placed Order: ";
var_dump($orderId);

Cannot create order Woocommerce rest Api php

I tried the following code and tried to post values from android to place an order but every time i test it on chrome it give http 500 error, and Android gives volly server error. Dont know where i am messing up, serious help would be appriciated. Thank You
Ask me if you need to take a look at the android Code, but i think that doesnot matter here because i am giving hard coded values in $data.
<?php
require_once( 'lib/woocommerce-api.php' );
$pageNum=1;
$pageNum=$_GET['page_num'];
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( 'https://www.move2mart.com/', 'ck_0afa3a49305683160fe34189553a660053bd4e6239', 'cs_7dc38a7b52c3fdd34qw61e34090be636ae3364b196', $options );
//$data=array();
$data=[
'payment_method' => 'cod',
'payment_method_title' => 'Cash on Delivery',
'set_paid' => false,
'billing' => [
'first_name' => 'John',
'last_name' => 'Doe',
'address_1' => '969 Market',
'city' => 'Karachi',
'email' => 'princeali#testing.com',
'phone' => '03123121995'
], 'line_items' => [
[
'product_id' => 779,
'quantity' => 1
]
]
];
print_r($client->post('orders', $data));
if($_POST !=null) {
}
else{
echo "Null POST Request";
}
} catch ( WC_API_Client_Exception $e ) {
echo $e->getMessage() . PHP_EOL;
echo $e->getCode() . PHP_EOL;
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
print_r( $e->get_request() );
print_r( $e->get_response() );
}
}
$orderData = array(
"order" => array(
"billing_address" => array(
array(
"first_name" => "",
"last_name" => "",
"company" => "",
"address_1" => "",
"address_2" => "",
"city" => "",
"state" => "",
"postcode" => "",
"country" => "",
"email" => "",
"phone" => "",
)
),
"shipping_address" => array(
array(
"first_name" => "",
"last_name" => "",
"company" => "",
"address_1" => "",
"address_2" => "",
"city" => "",
"state" => "",
"postcode" => "",
"country" => "",
)
),
"customer_id" => 1,
"line_items" => array(
array(
"product_id" => 1,
"quantity" => 1
)
)
)
);
$client->orders->create($orderData);
Would you please try above code?
Finally, I figured it out after some research. Below is working code of woocommerce checkout webservice that may Help you -
/*** Just Copy & Paste and change your varriables **/
//do your initial stuff
header('Content-type: application/json');
$json_file=file_get_contents('php://input');
$jsonvalue= json_decode($json_file,true);
$user_id = $jsonvalue['user_id'];
$product_id = $jsonvalue['product_id'];
$quantity = $jsonvalue['quantity'];
//start order data
$orderData = array(
"order" => array(
'payment_method' => 'paypal',
'payment_method_title' => 'Paypal',
'set_paid' => true,
"billing_address" => array(
"first_name" => "bfname",
"last_name" => "blname",
"company" => "testcompanybilling",
"address_1" => "sec8",
"address_2" => "e32",
"city" => "noida",
"state" => "Noida",
"postcode" => "99999",
"country" => "IN",
"email" => "test#gmail.com",
"phone" => "888899999999"
),
"shipping_address" => array(
"first_name" => "sfname",
"last_name" => "slname",
"company" => "testcompanyshipping",
"address_1" => "shakkarpur",
"address_2" => "laxminigar",
"city" => "New Delhi",
"state" => "Delhi",
"postcode" => "110092",
"country" => "IN",
"email" => "testsh#gmail.com",
"phone" => "11009999"
),
"customer_id" => $user_id,
"line_items" => array(
array(
"product_id" => $product_id,
"quantity" => $quantity
)
),
'shipping_lines' => array(
array(
'method_id' => 'flat_rate',
'method_title' => 'Flat Rate',
'total' => 10
)
)
)
);
//Create order usind order data
$data = $client->orders->create($orderData);
//echo '<pre>';
//print_r($data);
$result['success']='true';
$result['error']="0";
$result['msg']='Your order has been successfully placed.';
$result['data']=$data;
echo json_encode($result); `
cheers!!!

Categories