jeudi 23 novembre 2017

Testing Laravel route that listens for a webhook

Seems like I am missing something here, but I am struggling to implement a test for Laravel that integrates a SendOwl webhook.

Here is the doc I am using: http://ift.tt/2B6zaNI

I have tried a number of different things, but let's say:

public function testExample()
{
    $json = '{"order":{"access_allowed":true,"business_name":null,"business_vat_number":null,"buyer_address1":null,"buyer_address2":null,"buyer_city":null,"buyer_country":"GB","buyer_email":"mrbuyer@gmail.com","buyer_ip_address":"127.0.0.1","buyer_name":"Mr Buyer","buyer_postcode":null,"buyer_region":null,"cart":{"cart_items":[{"download_attempts":3,"product":{"id":2811,"license_type":"generated","member_types":["digital"],"name":"My Product","price":"£15.00","product_image_url":null,"product_type":"digital","shopify_variant_id":null},"quantity":1,"tax_rate":20.0,"valid_until":"2016-02-04T10:59:25Z"}],"completed_checkout_at":"2016-01-05T10:59:24Z"},"discount":null,"dispatched_at":null,"download_url":"http://ift.tt/2iLY3Yp","eu_resolved_country":"GB","eu_reverse_charge":null,"for_subscription":false,"gateway":"Stripe","gift_deliver_at":null,"gift_order":false,"giftee_email":null,"giftee_name":null,"id":"0000123456","licenses":[],"order_custom_checkout_fields":[],"paypal_email":null,"price_at_checkout":"£15.00","receiver_email":"mrbuyer@gmail.com","receiver_name":null,"settled_affiliate_fee":"£5.00","settled_currency":"GBP","settled_gateway_fee":"£0.38","settled_gross":"£18.00","settled_tax":"£3.00","state":"complete","subscription_management_url":null,"tag":null,"transactions":[{"alternate_pay_method_note":null,"created_at":"2016-01-05T10:59:24Z","gateway_transaction_id":"ch_fake001","net_price":"£15.60","payment_currency":"GBP","payment_gateway_fee":"£0.38","payment_gross":"£18.00","payment_tax":"£3.00","refund":false}],"unsubscribe_url":"http://ift.tt/2B6zcFk","validity_statement":"This link may be used up to 3 times before 2016-02-04 10:59:25 UTC when it will expire."}}';
    $this->call('post', '/listenhere', null, [], [], $json, [])->assertStatus(200);
}

Note I have already added the route to exclude in VerifyCSRFToken

The listenhere route currently just dd('whatever'); on the first line, since none of the controller code was even being run.

I also was trying to test it with Guzzle, and all I got was more errors such as telling me the third argument was a string not an array (it is) on createRequest or it "hangs up" if using ->request and spin endlessly until the server is restarted.

$json = '{"order":{"access_allowed":true,"business_name":null,"business_vat_number":null,"buyer_address1":null,"buyer_address2":null,"buyer_city":null,"buyer_country":"GB","buyer_email":"mrbuyer@gmail.com","buyer_ip_address":"127.0.0.1","buyer_name":"Mr Buyer","buyer_postcode":null,"buyer_region":null,"cart":{"cart_items":[{"download_attempts":3,"product":{"id":2811,"license_type":"generated","member_types":["digital"],"name":"My Product","price":"£15.00","product_image_url":null,"product_type":"digital","shopify_variant_id":null},"quantity":1,"tax_rate":20.0,"valid_until":"2016-02-04T10:59:25Z"}],"completed_checkout_at":"2016-01-05T10:59:24Z"},"discount":null,"dispatched_at":null,"download_url":"http://ift.tt/2iLY3Yp","eu_resolved_country":"GB","eu_reverse_charge":null,"for_subscription":false,"gateway":"Stripe","gift_deliver_at":null,"gift_order":false,"giftee_email":null,"giftee_name":null,"id":"0000123456","licenses":[],"order_custom_checkout_fields":[],"paypal_email":null,"price_at_checkout":"£15.00","receiver_email":"mrbuyer@gmail.com","receiver_name":null,"settled_affiliate_fee":"£5.00","settled_currency":"GBP","settled_gateway_fee":"£0.38","settled_gross":"£18.00","settled_tax":"£3.00","state":"complete","subscription_management_url":null,"tag":null,"transactions":[{"alternate_pay_method_note":null,"created_at":"2016-01-05T10:59:24Z","gateway_transaction_id":"ch_fake001","net_price":"£15.60","payment_currency":"GBP","payment_gateway_fee":"£0.38","payment_gross":"£18.00","payment_tax":"£3.00","refund":false}],"unsubscribe_url":"http://ift.tt/2B6zcFk","validity_statement":"This link may be used up to 3 times before 2016-02-04 10:59:25 UTC when it will expire."}}';
$response = $client->createRequest('POST', 'http://localhost:8008/listenhere', ["json"=>json_decode($json,true)]);
$response->send();
var_dump((string)$response->getBody());

Have tried so many different things and am not sure what I'm missing here.

Aucun commentaire:

Enregistrer un commentaire