pixelpeter / laravel5-woocommerce-api-client

Laravel 5 wrapper for the Woocommerce REST API
MIT License
125 stars 48 forks source link

post #32

Closed yourdigitalclub closed 6 years ago

yourdigitalclub commented 6 years ago

Hi this is not really an issue but I'm new to laravel so the usual way I'd send data via php won't work with laravel.

I came across your script and think it looks great, my goal is to be able to create a coupon for new members when they sign up... looking at your example code I amended as below to test. Would you say this looks correct

` $data = [ 'coupons' => [ 'code' => 'success', 'discount_type' => 'percent', 'amount' => '100', 'individual_use' => true, 'exclude_sale_items' => true, 'product_ids' => [ 7928,7915,7911,7910,7921,7937,7934,7883,7902 ] ] ];

    return Woocommerce::put('coupons', $data);`

this is my original script using automattic, but it won't work with laravel

`require DIR . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client( 'https://domain.com', 'ck_key', 'cs_secret', [ 'wp_api' => true, 'version' => 'wc/v2', 'query_string_auth' => true, ] );

$memberid = ''; $data = array( 'code' => 'success, 'discount_type' => 'percent', 'amount' => '100', 'individual_use' => true, 'exclude_sale_items' => true, 'product_ids' => [ 7928,7915,7911,7910,7921,7937,7934,7883,7902 ] );

use Automattic\WooCommerce\HttpClient\HttpClientException;

try { print_r($woocommerce->post('coupons', $data)); } catch (HttpClientException $e) { $e->getMessage(); // Error message. $e->getRequest(); // Last request data. $e->getResponse(); // Last response data. }`