-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Billplz\Contracts; | ||
|
||
interface PaymentCompletion | ||
{ | ||
/** | ||
* Get Webhook URL. | ||
*/ | ||
public function webhookUrl(): string; | ||
|
||
/** | ||
* Get Redirect URL. | ||
*/ | ||
public function redirectUrl(): ?string; | ||
|
||
/** | ||
* Convert to array. | ||
*/ | ||
public function toArray(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Billplz; | ||
|
||
class PaymentCompletion implements Contracts\PaymentCompletion | ||
{ | ||
/** | ||
* Webhook URL. | ||
* | ||
* @var string | ||
*/ | ||
protected $webhookUrl; | ||
|
||
/** | ||
* Redirect URL. | ||
* | ||
* @var string|null | ||
*/ | ||
protected $redirectUrl; | ||
|
||
/** | ||
* Construct Payment Completion. | ||
*/ | ||
public function __construct(string $callbackUrl, ?string $redirectUrl = null) | ||
{ | ||
$this->webhookUrl = $callbackUrl; | ||
$this->redirectUrl = $redirectUrl; | ||
} | ||
|
||
/** | ||
* Get Webhook URL. | ||
*/ | ||
public function webhookUrl(): string | ||
{ | ||
return $this->webhookUrl; | ||
} | ||
|
||
/** | ||
* Get Redirect URL. | ||
*/ | ||
public function redirectUrl(): ?string | ||
{ | ||
return $this->redirectUrl; | ||
} | ||
|
||
/** | ||
* Convert to array. | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'callback_url' => $this->webhookUrl, | ||
'redirect_url' => $this->redirectUrl, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Billplz\Tests; | ||
|
||
use Billplz\PaymentCompletion; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PaymentCompletionTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_generate_without_redirect_url() | ||
{ | ||
$payment = new PaymentCompletion('http://example.com/webhook/'); | ||
|
||
$this->assertSame('http://example.com/webhook/', $payment->webhookUrl()); | ||
$this->assertNull($payment->redirectUrl()); | ||
$this->assertSame([ | ||
'callback_url' => 'http://example.com/webhook/', | ||
'redirect_url' => null, | ||
], $payment->toArray()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_with_redirect_url() | ||
{ | ||
$payment = new PaymentCompletion('http://example.com/webhook/', 'http://example.com/redirect/'); | ||
|
||
$this->assertSame('http://example.com/webhook/', $payment->webhookUrl()); | ||
$this->assertSame('http://example.com/redirect/', $payment->redirectUrl()); | ||
$this->assertSame([ | ||
'callback_url' => 'http://example.com/webhook/', | ||
'redirect_url' => 'http://example.com/redirect/', | ||
], $payment->toArray()); | ||
} | ||
} |