Paypal webhook not contain custom_id - paypal

my code can generate a link for subscription and it work fine but when it send data to my webhook all field contained in the data except the custom_id.
Please advise how can I resolve this?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"plan_id": "P-97A61885CU957844JMFV",
"start_time": "2021-10-19T00:00:00Z",
"shipping_amount": {
"currency_code": "USD",
"custom_id": "xxxxdxxx",
"value": "10.00"
},
"subscriber": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "customer#example.com",
"shipping_address": {
"name": {
"full_name": "John Doe"
},
"address": {
"address_line_1": "2211 N First Street",
"address_line_2": "Building 17",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
},
"application_context": {
"brand_name": "SAMPLEBRAND",
"locale": "en-US",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
"payer_selected": "PAYPAL",
"payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://sample.com/webhook_paypal.php",
"cancel_url": "https://sample.com/webhook_paypal.php"
}
}');
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer '.$token;
$headers[] = 'Paypal-Request-Id: SUBSCRIPTION-21092019-001';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;
Here's webhook
{"id":"WH-82854424W5814533A-78W64324N5754181T","event_version":"1.0","create_time":"2021-10-20T03:35:20.009Z","resource_type":"subscription","resource_version":"2.0","event_type":"BILLING.SUBSCRIPTION.CREATED","summary":"Subscription created","resource":{"shipping_amount":{"currency_code":"USD","value":"10.0"},"start_time":"2021-10-21T00:00:00Z","quantity":"1","subscriber":{"email_address":"customer#example.com","name":{"given_name":"John","surname":"Doe"},"shipping_address":{"name":{"full_name":"John Doe"},"address":{"address_line_1":"2211 N First Street","address_line_2":"Building 17","admin_area_2":"TELEGRAM123","admin_area_1":"CA","postal_code":"95131","country_code":"US"}}},"create_time":"2021-10-20T03:35:19Z","links":[{"href":"https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-91B88793MP435642P","rel":"approve","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/billing/subscriptions/I-SYPXUU0207HG","rel":"edit","method":"PATCH"},{"href":"https://api.sandbox.paypal.com/v1/billing/subscriptions/I-SYPXUU0207HG","rel":"self","method":"GET"}],"id":"I-SYPXUU0207HG","plan_overridden":false,"plan_id":"P-1EC1893707675350SMFWSTEI","status":"APPROVAL_PENDING"},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-82854424W5814533A-78W64324N5754181T","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-82854424W5814533A-78W64324N5754181T/resend","rel":"resend","method":"POST"}]}

For a subscription to be approved, a payer account needs to subscribe.
A legacy integration method is to use the href with rel:approve that is returned from the API call.
The proper modern integration method is to use a JS SDK button, as documented in the Subscriptions Integration Guide.
Subscription creation can be either done directly in the JS (as that guide documents), or alternatively the JS createSubscription function can call a route on your server which returns the subscription ID from API creation. (The approve href is not used in this case; redirecting away from your site is bad).

Related

Migrating from API V1 to V2: How to getPaymentInstuctions after capture order?

I'm trying to migrate from API V1 to V2 in PHP. In V1, you could use this code to get further payment-instructions after executing a payment:
try {
$execution = new Paypal\Api\PaymentExecution();
$execution->setPayerId($sPayerId);
$payment = \Paypal\Api\Payment::get($sPaymentId, getApiContext());
$payment->execute($execution, getApiContext());
$payment = \Paypal\Api\Payment::get($sPaymentId, getApiContext()); // re-fetch payment with payment-instructions
if ($payment->getPaymentInstruction())
{ $sBankName = $payment->getPaymentInstruction()->recipient_banking_instruction->bank_name;
$sBandAccountNumber = $payment->getPaymentInstruction()->recipient_banking_instruction->international_bank_account_number;
...
}
}
catch(PayPal\Exception\PayPalConnectionException $ex) {
...
}
It's important for us to display the payment-instructions to our customer: If they use the "pay later"/"pay via invoice"-feature, they need to know to which bank and account to transfer the money to.
In API V2, you use this code to capture an authorized order:
$request = new PayPalCheckoutSdk\Orders\OrdersCaptureRequest($sOrderId);
try {
$response = getClient()->execute($request);
}
catch(PayPalHttp\HttpException $exception) {
....
}
So what are the next steps to get the payment-instructions now?
The field was not documented for the v1/payments API.
For v2/checkout/orders , a payment_instruction field is documented as an order creation request field (within purchase_units) and response field.
A similar field exists when capturing an authorization.
For Pay Upon Invoice, there is a processing_instruction field.
In all these cases, the fields do not contain information regarding "which bank and account to transfer the money to" or similar.
However, for PUI there is a response field payment_source.pay_upon_invoice.deposit_bank_details . Perhaps this is what you are looking for.
{
"id": "5O190127TN364715T",
"intent": "CAPTURE",
"status": "COMPLETED",
"processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",
"payment_source": {
"pay_upon_invoice": {
"birth_date": "1990-01-01",
"name": {
"given_name": "John",
"surname": "Doe"
},
"email": "buyer#example.com",
"phone": {
"national_number": "6912345678",
"country_code": "49"
},
"billing_address": {
"address_line_1": "Schönhauser Allee 84",
"admin_area_2": "Berlin",
"postal_code": "10439",
"country_code": "DE"
},
"payment_reference": "b8a1525dlYzu6Mn62umI",
"deposit_bank_details": {
"bic": "DEUTDEFFXXX",
"bank_name": "Deutsche Bank",
"iban": "DE89370400440532013000",
"account_holder_name": "Paypal - Ratepay GmbH - Test Bank Account"
}
}
},
"purchase_units": [
....
],
"links": [
....
]
}

FB messenger checkbox messaging_optins send message to user_ref_id not working "You cannot send messages to this id"

I tried to send a message to my customer after they put an order if they check the FB Messenger checkbox plugin on the checkout page.
I already follow step-by-step the FB docs of this plugin
https://developers.facebook.com/docs/messenger-platform/discovery/checkbox-plugin/
All are fine and works until I want to try to send the message to the user_ref_id that I defined before and it just thrown error to me.
{
"error": {
"message": "(#100) Parameter error: You cannot send messages to this id",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Aev08w-rkwIfurCKj79g2R0"
}
I was succeed and able to receive the webhook messaging_optins as like below
{
"value": {
"object": "page",
"entry": [{
"id": "xxxxx",
"time": 1617868589319,
"messaging": [{
"recipient": {
"id": "xxxxx"
},
"timestamp": 1617868589319,
"optin": {
"ref": "test=haha",
"user_ref": "2020092411511430212"
}
}]
}]
}
I already check my app_id and page_id both are correct, and I also use the access_token that I generate from FB developer Messenger section is correct too.
Here's my code to send the message
$messageData = [
"recipient" => [
"id" => '202009241151143024'
],
"message" => [
"text" => 'hello'
]
];
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token=xxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($messageData));
$result = curl_exec($ch);
curl_exec($ch);
I don't know where's the mistakes or maybe I skipped some step when setting it?
Thanks in advance.
I already found my mistakes
i use id instead of user_ref when I tried to send a message to my customer.
Here's the correction code when send the message.
$messageData = [
"recipient" => [
"user_ref" => '202009241151143024'
],
"message" => [
"text" => 'hello'
]
];
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token=xxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($messageData));
$result = curl_exec($ch);
curl_exec($ch);

Where is the PayPal Subscription ID and Transaction ID in a PAYMENT.SALE.COMPLETED webhook event? How to get their details?

I'm using PayPal subscription API with php.
So far I know that with a successful payment the PAYMENT.SALE.COMPLETED event is triggered. But the object contains only a billing agreement id and seems not related to the subscription. How can I get more details about customer and the payment?
Content of example webhook
{
"id": "WH-1J525465EH157100Y-81K24252LY536784P",
"create_time": "2021-03-10T18:22:33.292Z",
"resource_type": "sale",
"event_type": "PAYMENT.SALE.COMPLETED",
"summary": "Payment completed for EUR 5.0 EUR",
"resource": {
"billing_agreement_id": "I-8XRLDA4MNEW3",
"amount": {
"total": "5.00",
"currency": "EUR",
"details": {
"subtotal": "5.00"
}
},
"payment_mode": "INSTANT_TRANSFER",
"update_time": "2021-03-10T18:22:13Z",
"create_time": "2021-03-10T18:22:13Z",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee": {
"currency": "EUR",
"value": "0.45"
},
"protection_eligibility": "ELIGIBLE",
"links": [
{
"method": "GET",
"rel": "self",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/1P642136UK709905M"
},
{
"method": "POST",
"rel": "refund",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/1P642136UK709905M/refund"
}
],
"id": "1P642136UK709905M",
"state": "completed",
"invoice_number": ""
},
"status": "SUCCESS",
"transmissions": [
{
"webhook_url": "https://musily.de/payment/webhook/paypal.php",
"http_status": 200,
"reason_phrase": "HTTP/1.1 200 Connection established",
"response_headers": {
"Accept-Ranges": "none",
"Server": "Apache/2.4.46 (Unix)",
"Cache-Control": "max-age=172800",
"Expires": "Fri, 12 Mar 2021 18:23:16 GMT",
"Content-Length": "65",
"Date": "Wed, 10 Mar 2021 18:23:16 GMT",
"X-Powered-By": "PHP/7.3.27",
"Content-Type": "text/html"
},
"transmission_id": "a7472af0-81cd-11eb-aacd-47b3747d966f",
"status": "SUCCESS",
"timestamp": "2021-03-10T18:23:03Z"
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-1J525465EH157100Y-81K24252LY536784P",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-1J525465EH157100Y-81K24252LY536784P/resend",
"rel": "resend",
"method": "POST",
"encType": "application/json"
}
],
"event_version": "1.0"
}
"billing_agreement_id": "I-8XRLDA4MNEW3",
That is your subscription's ID right there.
"id": "1P642136UK709905M",
That is your PayPal transaction / sale / capture ID right there.
"links": [
{
"method": "GET",
"rel": "self",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/1P642136UK709905M"
},
{
There's how to get details about the sale (the v2/payments/captures API might also work, not sure)
As #Preston-PHX said billing_agreement_id is a subscription id, but if you need to get subscription name and similar details:
Get billing_agreement_id and call subscriptions api, reply would be details on the customer and small details on subscription:
function getsubdetails($id)
{
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer '.$this->token;
$url = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/'.$id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$server_output = curl_exec($ch);
return $server_output;
curl_close ($ch);
}
Get plan_id and call plans api, reply would be all details on subscription:
public function getplandetails($id)
{
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer '.$this->token;
$url = 'https://api-m.sandbox.paypal.com/v1/billing/plans/'.$id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$server_output = curl_exec($ch);
return $server_output;
curl_close ($ch);
}
Full code:
include 'paypal.php'; //contains above code inside Paypal class
$paypal = new Paypal;
$paypal->setcredentials($clientid,$secret); //setting api credentials, create this function near above code
$paypal->gettoken(); // initiating token, create this function near above code
$subdetails = $paypal->getsubdetails($planid); //sending billing_agreement_id
$subdetails2 = json_decode($subdetails,true);
$planid = $subdetails2['plan_id']; //received plan_id
$plandetails = $paypal->getplandetails($planid); // sending it to get subscription name
$plandetails2 = json_decode($plandetails, true);
$this->planname = $plandetails2['name'];

curl issue when trying to use PayPal REST Orders API for PayPal Market Places

I'm attempting to follow the Orders Integration Guide as shown in this documentation: https://developer.paypal.com/docs/marketplaces/orders/integration-guide/
I was able to complete getting the access token and everything up to the Create Order section. However, when I try to make the Create Order call in my localhost, I am getting this as the ouput:
Notice: Undefined variable: data in C:\xampp\htdocs\ordersAPI.php on line 75
Notice: Undefined variable: data in C:\xampp\htdocs\ordersAPI.php on line 85
I have been racking my brain trying to figure this out why this is happening. I am have been looking through all sorts of stack questions but I can’t figure out what I’m missing. It seems like I did define the ‘data’ variable so I’m not sure where I’m going wrong and why I’m getting 1 returned.
I am also getting an error of 500 returned when trying to test my credentials on another test site I found. So I am not sure if it’s something wrong with the account, or with my code. I wouldn’t assume it’s an account issue since it’s giving an error about undefined variable.
<?php
$data = '{
"purchase_units": [
{
"reference_id": "item_bought",
"description": "item_description",
"amount": {
"currency": "USD",
"details": {
"subtotal": "100.00",
"shipping": "0.00",
"tax": "0.00"
},
"total": "100.00"
},
"payee": {
"email": "selleraccount#gmail.com"
},
"items": [
{
"name": "widget",
"sku": "sku03",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
},
{
"name": "gadget",
"sku": "sku04",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
}
],
"shipping_address": {
"recipient_name": "Billy Bob",
"line1": "123 Test Street",
"line2": "Building 17",
"city": "Lawrence",
"country_code": "US",
"postal_code": "66047",
"state": "KS",
"phone": "(123) 456-7890"
},
"shipping_method": "United Postal Service",
"partner_fee_details": {
"receiver": {
"email": "ordersapitest#gmail.com"
},
"amount": {
"value": "20.00",
"currency": "USD"
}
},
"payment_linked_group": 1,
"custom": "silk",
"invoice_number": "invoice_1234",
"payment_descriptor": "FakeShop"
}
],
"redirect_urls": {
"return_url": "https://marketplace.com/return",
"cancel_url": "https://marketplace.com/cancel"
}
}';
function marketplace(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/checkout/orders");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer A21AAFA2Ty6rGJc74cTukhyCRz5pHU3vX736qtr4qSfhDmEzawiU8u91w69GxZtmYDalxaljYbeqi6ovZmOQCyTEETom8ZkFQ",
"PayPal-Request-Id: 5Qy7c8A1H8iQqyp",
"Content-length: ".strlen($data))
);
$httpResponse= curl_exec($ch);
if(!$httpResponse) {
$response = "API failed: ".curl_error($ch).'('.curl_errno($ch).')';
return $response;
}
$httpResponseAr = explode("&", $httpResponse);
return $httpResponseAr;
}
$result = marketplace();
echo $json = json_encode($result, JSON_PRETTY_PRINT);
//print_r($result);
?>
The $data variable is not being passed as a parameter in the marketplace function on line 71 and it is not being passed as a parameter in the function call on line 96. This is what is causing the error.
Also, while the 'CREATE ORDER' call will work, if you attempt the next step which is the 'PAY FOR ORDER' call, the error 500 will be generated because you are trying to use the MarketPlaces API for PayPal and are not yet approved for the MarketPlaces API.
Please see this article on PayPal’s site.
https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ2138&expand=true&locale=en_US
You can also find more information on the PP4MP at:
https://developer.paypal.com/docs/marketplaces/pp4mp/

how to create bundle product in Magento 2 by REST API?

I want to create a bundle product through REST API in postman client, but i can't seem to find the right API to create the same. I can add bundle options through REST API but to add those options i need to have a bundle product.So can someone help me with the issue?
I had some issue trying to create a bundle product with the Magento 2 API but finally figured it out, as this post come up every time I googled I will answer here with the request you need to make through postman in order to create a bundle product. Using the url http://{{host}}/rest/default/V1/products with method POST and the Authorization header with the token received from http://{{host}}/rest/default/V1/integration/admin/token, you will have to send the following body as JSON in order to create a bundle product with associated products:
{
"product": {
"sku": "some-bundle-sku",
"name": null,
"attribute_set_id": 4,
"price": 1000,
"status": 1,
"visibility": 1,
"type_id": "bundle",
"created_at": "2018-01-01 00:00:00",
"updated_at": "2018-01-01 00:00:00",
"extension_attributes": {
"stock_item": {
"qty": 100
},
"website_ids": [
1
],
"category_links": [],
"bundle_product_options": [
{
"option_id": 0,
"position": 1,
"sku": "bundle-option-sku",
"title": "Bundle products",
"type": "select",
"required": true,
"product_links": [
{
"sku": "some prod 1 sku",
"option_id": 1,
"qty": 1,
"position": 1,
"is_default": false,
"price": null,
"price_type": null,
"can_change_quantity": 0
},
{
"sku": "some prod 2 sku",
"option_id": 1,
"qty": 1,
"position": 2,
"is_default": false,
"price": null,
"price_type": null,
"can_change_quantity": 0
}
]
}
]
},
"custom_attributes": [
{
"attribute_code": "price_view",
"value": "0"
}
]
},
"saveOptions": true
}
Make sure that the products you are adding in "product_links" exist otherwise it will not create the bundle product. Pay attention to "bundle_product_options", this needs to be an array of options, my mistake was that I was trying to create a single option and I was not passing it within an array.
To Create Bundle Product in Magento 2 via REST API:
//API URL for authentication
$apiURL="http://{host}/rest/V1/integration/admin/token";
//parameters passing with URL
$data = array("username" => "<username>", "password" => "<password>");
$data_string = json_encode($data);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string)));
$token = curl_exec($ch);
//decoding generated token and saving it in a variable
$token = json_decode($token);
print_r($token);
//Using above token into header
$headers = array("Content-Type: application/json", "Authorization: Bearer ".$token);
//API URL to Add Product(s) in Magento
$requestUrl='http://{host}/rest/default/V1/products';
$toBeAdded = '{
"product": {
"sku": "some-bundle-sku",
"name": Demo-Bundle,
"attribute_set_id": 4,
"price": 1000,
"status": 1,
"visibility": 1,
"type_id": "bundle",
"created_at": "2019-04-28 00:00:00",
"updated_at": "2019-04-28 00:00:00",
"extension_attributes": {
"stock_item": {
"qty": 100
},
"website_ids": [
1
],
"category_links": [],
"bundle_product_options": [
{
"option_id": 0,
"position": 1,
"sku": "bundle-option-sku",
"title": "Bundle products",
"type": "select",
"required": true,
"product_links": [
{
"sku": "Sample",
"option_id": 1,
"qty": 1,
"position": 1,
"is_default": false,
"price": 20,
"price_type": null,
"can_change_quantity": 0
},
{
"sku": "Demo",
"option_id": 1,
"qty": 1,
"position": 2,
"is_default": false,
"price": 30,
"price_type": null,
"can_change_quantity": 0
}
]
}
]
},
"custom_attributes": [
{
"attribute_code": "price_view",
"value": "0"
}
]
},
"saveOptions": true
}';
$ch = curl_init();
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$options = array(
CURLOPT_POSTFIELDS=>$toBeAdded
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$result= json_decode($result);
echo "<pre>";
print_r($result);
This should resolve your issues. Also make sure Assigned User has Access to desired Resources and the product you are adding as bundle options must exit on your Magento environment.
Happy coding ! Cheers !
To create bundle product in Magento 2 by REST API, We will be followed some step's see below:
STEP 1- First let us write the configurations (URL's,username,password)
// configuration Data
$url="http://www.example.com/index.php/";
$token_url=$url."rest/V1/integration/admin/token";
$product_url=$url. "rest/V1/products";
$username="your admin username";
$password="your admin password";
$product_links = array(
array("sku"=>"cpu1","qty"=>1)
);
STEP 2- Then let us get access token
//Authentication rest API magento2, get access token
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$data_string = json_encode($data);
$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$adminToken= json_decode($token);
STEP 3- No let us prepare the Product data
// Create the Configurable Product
$configProductData = array(
'sku' => 'bundle'. uniqid(),
'name' => 'Bundle' . uniqid(),
'visibility' => 4, /*'catalog',*/
'type_id' => 'bundle',
'price' => 99.95,
'status' => 1,
'attribute_set_id' => 4,
'weight' => 1,
'custom_attributes' => array(
array( 'attribute_code' => 'category_ids', 'value' => ["42","41","32"] ),
array( 'attribute_code' => 'description', 'value' => 'Description' ),
array( 'attribute_code' => 'short_description', 'value' => 'Short Description' ),
array( 'attribute_code' => 'price_view', 'value' => '0' ),
array( 'attribute_code' => 'price_type', 'value' => '0' ),
),
'extension_attributes' => array("bundle_product_options"=>array(
array("title"=>"CPU","type"=>"select","product_links"=>$product_links),
),
)
);
$productData = json_encode(array('product' => $configProductData));
STEP 4- At the end we will send the product data to magento to create the product
$setHaders = array('Content-Type:application/json','Authorization:Bearer '.$adminToken);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $product_url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHaders);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);