Skip to content

Commit

Permalink
fix make payment link
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Bak committed Jan 12, 2024
1 parent 4f7a41b commit bd9bc80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ $createdPayment = \Netbums\Quickpay\Quickpay::api()->payments()->create(
```
After a payment is created you can create a payment link for it, and redirect the user to the payment link.

#### Create a payment link
```php
$paymentLinkData = new \Netbums\Quickpay\DataObjects\PaymentLink(
id: 437296737,
amount: 100
);

$paymentLink = \Netbums\Quickpay\Quickpay::api()->payments()->createLink($paymentLinkData);
```
This will return a URL, that you can redirect the user to.

#### Update a payment
```php
```
Expand Down
16 changes: 8 additions & 8 deletions src/DataObjects/PaymentLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
public function __construct(
public int $id, // transaction id
public int $amount, // Amount to authorize
public ?string $language,
public ?string $continue_url,
public ?string $cancel_url,
public ?string $callback_url,
public ?string $language = null,
public ?string $continue_url = null,
public ?string $cancel_url = null,
public ?string $callback_url = null,
) {
}

Expand All @@ -19,10 +19,10 @@ public static function fromArray(array $data): static
return new static(
id: $data['id'],
amount: $data['amount'],
language: $data['language'],
continue_url: $data['continue_url'],
cancel_url: $data['cancel_url'],
callback_url: $data['callback_url'],
language: $data['language'] ?? null,
continue_url: $data['continue_url'] ?? null,
cancel_url: $data['cancel_url'] ?? null,
callback_url: $data['callback_url'] ?? null,
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Resources/PaymentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public function create(Payment $payment): array
*
* @throws CreatePaymentLinkFailed
*/
public function createLink(int $id, PaymentLink $paymentLink): array
public function createLink(PaymentLink $paymentLink): array
{
$id = $paymentLink->id;
$this->method = 'put';
$this->endpoint = 'payments/'.$id.'/link';
$this->data = $paymentLink->toArray();
Expand Down

0 comments on commit bd9bc80

Please sign in to comment.