diff --git a/resources/views/javaScriptSetup.blade.php b/resources/views/javaScriptSetup.blade.php index 3fef3d6..3514a48 100644 --- a/resources/views/javaScriptSetup.blade.php +++ b/resources/views/javaScriptSetup.blade.php @@ -3,5 +3,5 @@ @if(config('paddle.sandbox_environment')) Paddle.Environment.set('sandbox'); @endif - Paddle.Setup(@json(['vendor' => (int) config('paddle.vendor_id')])); + Paddle.Setup(@json(['vendor' => (int) $vendorId])); diff --git a/src/Api/Request.php b/src/Api/Request.php index 6054e28..b0581c4 100644 --- a/src/Api/Request.php +++ b/src/Api/Request.php @@ -98,12 +98,14 @@ public function send() $method = $this->method; - $data = $this->getData() + ['vendor_id' => config('paddle.vendor_id')]; + $data = ['vendor_id' => config('paddle.vendor_id')]; if ($method === static::METHOD_POST) { $data['vendor_auth_code'] = config('paddle.vendor_auth_code'); } + $data = array_merge($data, $this->getData()); + $url = $this->url(); if (config('paddle.sandbox_environment')) { diff --git a/src/PaddleServiceProvider.php b/src/PaddleServiceProvider.php index a226508..82dca4b 100755 --- a/src/PaddleServiceProvider.php +++ b/src/PaddleServiceProvider.php @@ -27,8 +27,15 @@ public function boot() $this->loadViewsFrom(__DIR__ . '/../resources/views', 'paddle'); - Blade::directive('paddle', function () { - return ""; + + Blade::directive('paddle', function ($vendorId = false) { + if (!$vendorId) { + $vendorId = config('paddle.vendor_id'); + } + + return " " . $vendorId . "]); + ?>"; }); } diff --git a/tests/DirectiveTest.php b/tests/DirectiveTest.php index 3a6a1b1..0eb5008 100644 --- a/tests/DirectiveTest.php +++ b/tests/DirectiveTest.php @@ -47,4 +47,19 @@ public function it_includes_paddle_js_with_the_sandbox_environment() $this->assertStringContainsString("Paddle.Environment.set('sandbox');", $rendered); $this->assertStringContainsString('Paddle.Setup({"vendor":20});', $rendered); } + + /** @test */ + public function it_includes_paddle_js_with_vendor_id() + { + View::addLocation(__DIR__); + config([ + 'paddle' => [ + 'vendor_id' => 20, + ], + ]); + + $rendered = (string) view('dummy-vendor', ['vendor' => 50]); + + $this->assertStringContainsString('Paddle.Setup({"vendor":50});', $rendered); + } } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 632e82c..46e2bbb 100755 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -69,4 +69,31 @@ public function it_throws_an_exception_if_the_given_data_is_invalid() $this->fail('Should have thrown InvalidDataException'); } + + /** @test */ + public function it_can_set_the_vendor_keys_into_payload_by_array() + { + config([ + 'paddle' => [ + 'vendor_id' => 20, + 'vendor_auth_code' => '123', + ], + ]); + $request = (new Api)->product()->generatePayLink([ + 'product_id' => 10, + 'customer_email' => 'test@example.com', + 'passthrough' => ['team_id' => 20], + 'vendor_id' => 50, + 'vendor_auth_code' => 'efg' + ]); + + $this->assertEquals([ + 'product_id' => 10, + 'customer_email' => 'test@example.com', + 'passthrough' => json_encode(['team_id' => 20]), + 'vendor_id' => 50, + 'vendor_auth_code' => 'efg' + + ], $request->getData()); + } } diff --git a/tests/dummy-vendor.blade.php b/tests/dummy-vendor.blade.php new file mode 100644 index 0000000..5a7c1d6 --- /dev/null +++ b/tests/dummy-vendor.blade.php @@ -0,0 +1 @@ +@paddle($vendor) \ No newline at end of file