Skip to content

Commit

Permalink
fixed infusionsoft version
Browse files Browse the repository at this point in the history
  • Loading branch information
azzarip committed Jul 19, 2024
1 parent 96df82d commit 7fd692e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public function user()
return new V1\User();
}

public function submitForm(string $form_xid, array $data, array $headers = [])
public function submitForm(string $form_xid, string $infusionsoft_version, array $data, array $headers = [])
{
return new Services\Form($form_xid, $data, $headers);
return new Services\Form($form_xid, $infusionsoft_version, $data, $headers);
}
}
6 changes: 4 additions & 2 deletions src/Services/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
namespace KeapGeek\Keap\Services;

use Illuminate\Support\Facades\Http;
use KeapGeek\Keap\Exceptions\KeapException;

class Form
{
public function __construct(string $form_xid, array $data, array $headers = [])
public function __construct(string $form_xid, string $infusionsoft_version, array $data, array $headers = [])
{
if (empty(config('keap.app_name'))) {
return;
throw new KeapException('App_name not set in configuration.');
}
$data['inf_form_xid'] = $form_xid;
$data['infusionsoft_version'] = $infusionsoft_version;

Http::withHeaders($headers)->asForm()->post('https://'.config('keap.app_name').'.infusionsoft.com/app/form/process/'.$form_xid, $data);
}
Expand Down
13 changes: 5 additions & 8 deletions tests/Feature/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use KeapGeek\Keap\Exceptions\KeapException;
use KeapGeek\Keap\Facades\Keap;
use KeapGeek\Keap\Services\Form;

Expand All @@ -10,19 +11,15 @@
Http::fake();
});

test('facade returns a Form Service', function () {
expect(Keap::submitForm('::xid::', []))->toBeInstanceOf(Form::class);
});

test('if config is not set no Http call', function () {
test('if config is not set throws Exception', function () {
Config::set('keap.app_name', null);
Keap::submitForm('::xid::', []);
Http::assertNothingSent();
});
Keap::submitForm('::xid::', '1.2.3', []);
})->throws(KeapException::class);

test('if config is set it sends Http call', function () {
Config::set('keap.app_name', 'aaa111');
Keap::submitForm('::xid::', []);
Keap::submitForm('::xid::', '1.2.3', []);
Http::assertSent(function ($request) {
return $request->url() === 'https://aaa111.infusionsoft.com/app/form/process/::xid::' &&
$request->method() === 'POST';
Expand Down

0 comments on commit 7fd692e

Please sign in to comment.