We have a product configured as simple subscription product.
If you buy that product on the shop site directly, it will automatically create a subscription for this order after purchase.
We want to achieve the same behaviour with a REST-API call.
We know there is a create subscription endpoint but we explicitly don't want to use this.
We want the same way like on the page.
So we tried to use the create a order endpoint and added the product as line_Item (using ruby code here):
data = { customer_id: 1, currency: 'EUR', line_items: [{product_id: 1, quantity: 1}] }
response = woocommmerce.post('orders', data).parsed_response
puts response
{"id"=>532,
"parent_id"=>0,
"status"=>"pending",
"currency"=>"EUR",
"version"=>"6.9.4",
"prices_include_tax"=>true,
"date_created"=>"2022-10-10T14:34:11",
"date_modified"=>"2022-10-10T14:34:11",
"discount_total"=>"0.00",
"discount_tax"=>"0.00",
"shipping_total"=>"0.00",
"shipping_tax"=>"0.00",
"cart_tax"=>"0.00",
"total"=>"1.00",
"total_tax"=>"0.00",
"customer_id"=>1,
"order_key"=>"wc_order_xxx",
"billing"=> ...,
"shipping"=>...,
"payment_method"=>"",
"payment_method_title"=>"",
"transaction_id"=>"",
"customer_ip_address"=>"",
"customer_user_agent"=>"",
"created_via"=>"rest-api",
"customer_note"=>"",
"date_completed"=>nil,
"date_paid"=>nil,
"cart_hash"=>"",
"number"=>"532",
"meta_data"=>[{"id"=>9854, "key"=>"_gzd_version", "value"=>"3.10.6"}],
"line_items"=>
[{"id"=>23,
"name"=>"Abo (3 Months)",
"product_id"=>1,
"variation_id"=>0,
"quantity"=>1,
"tax_class"=>"19-mwst",
"subtotal"=>"1.00",
"subtotal_tax"=>"0.00",
"total"=>"1.00",
"total_tax"=>"0.00",
"taxes"=>[],
"meta_data"=>...,
"sku"=>"",
"price"=>1,
"image"=>{"id"=>"187", "src"=>"placeholder.png"},
"parent_name"=>nil}],
"tax_lines"=>[],
"shipping_lines"=>[],
"fee_lines"=>[],
"coupon_lines"=>[],
"refunds"=>[],
"payment_url"=>"https://test.de/kasse/order-pay/532/?pay_for_order=true&key=wc_order_xxx&force_pay_order=1",
"is_editable"=>true,
"needs_payment"=>true,
"needs_processing"=>true,
"date_created_gmt"=>"2022-10-10T14:34:11",
"date_modified_gmt"=>"2022-10-10T14:34:11",
"date_completed_gmt"=>nil,
"date_paid_gmt"=>nil,
"shipments"=>[],
"shipping_status"=>"no-shipping-needed",
"currency_symbol"=>"€",
"parcel_delivery_opted_in"=>"",
"direct_debit"=>{"holder"=>"", "iban"=>"", "bic"=>"", "mandate_id"=>""},
"_links"=>...
}
That looks fine.
In our current flow we will open the payment_url from above and complete the checkout. That also works fine.
But it does not create a subscription, like it does on the shop page.
What am I missing here? Is this process possible with REST-API calls?
Thanks in advance.
Regards, spa