Skip to content

Commit 606b938

Browse files
Merge pull request #46 from alexstewartja/6.0.x
+ Release 6.0.0 - Updated BitPay client dependency to v7.1.0 - Bumped minimum PHP version to 7.4 - Implemented the invoice webhook/notification resend action - Isolated implementation of the `Refunds` resource
2 parents 84232c7 + 1994a89 commit 606b938

9 files changed

+193
-110
lines changed

.github/workflows/php.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
build_php_73:
10+
build_php_74:
1111

1212
runs-on: ubuntu-latest
1313

@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup PHP with PECL extension
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: '7.3'
20+
php-version: '7.4'
2121

2222
- name: Validate composer.json and composer.lock
2323
run: composer validate --strict
@@ -66,3 +66,33 @@ jobs:
6666

6767
- name: Run test suite
6868
run: composer run-script test
69+
70+
build_php_81:
71+
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- uses: actions/checkout@v2
76+
77+
- name: Setup PHP with PECL extension
78+
uses: shivammathur/setup-php@v2
79+
with:
80+
php-version: '8.1'
81+
82+
- name: Validate composer.json and composer.lock
83+
run: composer validate --strict
84+
85+
- name: Cache Composer packages
86+
id: composer-cache
87+
uses: actions/cache@v2
88+
with:
89+
path: vendor
90+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
91+
restore-keys: |
92+
${{ runner.os }}-php-
93+
94+
- name: Install dependencies
95+
run: composer install --prefer-dist --no-progress
96+
97+
- name: Run test suite
98+
run: composer run-script test

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
All notable changes to `vrajroham/laravel-bitpay` will be documented in this file
44

55
---
6+
7+
#### v6.0.0 - 2022-12-18
8+
9+
* Updated BitPay client dependency to v7.1.0
10+
* Bumped minimum PHP version to 7.4
11+
* Implemented the invoice webhook/notification resend action
12+
* Isolated implementation of the `Refunds` resource
13+
14+
#### v5.3.0 - 2022-06-20
15+
16+
* Fixed issues, updated deps & corrected typos by @alexstewartja in https://github.com/vrajroham/laravel-bitpay/pull/42
17+
618
#### v5.0.1 - 2021-12-18
719

820
* Make newLine() calls compatible with Laravel versions below 8 by @Ririshi in https://github.com/vrajroham/laravel-bitpay/pull/41

README.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
LaravelBitPay enables you and your business to transact in Bitcoin, Bitcoin Cash and 10+ other BitPay-supported
1111
cryptocurrencies within your Laravel application.
1212

13-
> Requires PHP 7.3+
13+
> Requires PHP 7.4+
1414
1515
## :warning: Migration From v4 :warning:
1616

@@ -19,6 +19,7 @@ If upgrading from v4, please follow [MIGRATION.md](./MIGRATION.md)
1919
## Supported Resources
2020

2121
- :white_check_mark: [Invoices](https://bitpay.com/api/#rest-api-resources-invoices)
22+
- :white_check_mark: [Refunds](https://bitpay.com/api/#rest-api-resources-refunds)
2223
- :white_check_mark: [Bills](https://bitpay.com/api/#rest-api-resources-bills)
2324
- :white_check_mark: [Subscriptions](https://bitpay.com/api/#rest-api-resources-subscriptions)
2425
- :white_check_mark: [Settlements](https://bitpay.com/api/#rest-api-resources-settlements)
@@ -43,6 +44,7 @@ If upgrading from v4, please follow [MIGRATION.md](./MIGRATION.md)
4344
+ [Create an invoice](#create-an-invoice)
4445
+ [Retrieve an existing invoice](#retrieve-an-existing-invoice)
4546
+ [Retrieve a list of existing invoices](#retrieve-a-list-of-existing-invoices)
47+
+ [Refunds](#refunds)
4648
+ [Refund an invoice](#refund-an-invoice)
4749
+ [Retrieve a refund request](#retrieve-a-refund-request)
4850
+ [Retrieve all refund requests on an invoice](#retrieve-all-refund-requests-on-an-invoice)
@@ -141,8 +143,10 @@ php artisan laravel-bitpay:createkeypair
141143

142144
<center><img src="https://i.ibb.co/JvP3bQb/create-key-pair-command.png" title="Create Key-Pair Command" alt="Create Key-Pair Command"/></center>
143145

144-
> :information_source: By default, the command will use the (valid) existing private key located at `BITPAY_PRIVATE_KEY_PATH`.
145-
> You may specify the `--fresh` or `-f` option to explicitly generate a fresh private key, from which tokens are derived.
146+
> :information_source: By default, the command will use the (valid) existing private key located
147+
> at `BITPAY_PRIVATE_KEY_PATH`.
148+
> You may specify the `--fresh` or `-f` option to explicitly generate a fresh private key, from which tokens are
149+
> derived.
146150
147151
After successful API Token generation, you will need to approve it by visiting the provided link.
148152

@@ -173,7 +177,8 @@ Route::bitPayWebhook(); // https://example.com/laravel-bitpay/webhook
173177
Route::bitPayWebhook('receive/webhooks/here'); // https://example.com/receive/webhooks/here
174178
```
175179

176-
> :information_source: To retrieve your newly created webhook route anywhere in your application, use: `route('laravel-bitpay.webhook.capture')`
180+
> :information_source: To retrieve your newly created webhook route anywhere in your application,
181+
> use: `route('laravel-bitpay.webhook.capture')`
177182
178183
LaravelBitPay also offers the convenience of auto-populating your configured webhook url on applicable resources.
179184
Specifically when:
@@ -345,6 +350,19 @@ $endDate = date('Y-m-d');
345350
$invoices = LaravelBitpay::getInvoices($startDate, $endDate);
346351
```
347352

353+
#### Request an Invoice webhook to be resent
354+
355+
```php
356+
// True if the webhook has been resent for the current invoice status, false otherwise.
357+
$webhookResent = LaravelBitpay::requestInvoiceWebhook('invoiceId_sGsdVsgheF');
358+
```
359+
360+
### Refunds
361+
362+
Refund requests are full or partial refunds associated to an invoice. Fully paid invoices can be refunded via the
363+
merchant's authorization to issue a refund, while underpaid and overpaid invoices are automatically executed by BitPay
364+
to issue the underpayment or overpayment amount to the customer.
365+
348366
#### Refund an invoice
349367

350368
The item Jane purchased was dead on arrival. Give back the lady her crypto:
@@ -921,7 +939,8 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
921939

922940
## Security
923941

924-
If you discover any security related issues, please email [email protected] or [email protected] instead of using the issue tracker.
942+
If you discover any security related issues, please email [email protected] or [email protected] instead of
943+
using the issue tracker.
925944

926945
## Credits
927946

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.3 || ^8.0",
26+
"php": "^7.4 || ^8.0 || ^8.1",
2727
"ext-json": "*",
28-
"bitpay/sdk": "~6.0.2"
28+
"bitpay/sdk": "~7.1.0"
2929
},
3030
"require-dev": {
3131
"phpunit/phpunit": ">=9.5"

src/Actions/ManageInvoices.php

+7-95
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Vrajroham\LaravelBitpay\Actions;
44

55
use BitPaySDK\Exceptions\BitPayException;
6-
use BitPaySDK\Exceptions\RefundCancellationException;
76
use BitPaySDK\Model\Invoice\Buyer;
87
use BitPaySDK\Model\Invoice\Invoice;
9-
use BitPaySDK\Model\Invoice\Refund;
108
use Vrajroham\LaravelBitpay\Constants\WebhookAutoPopulate;
119

1210

@@ -103,103 +101,17 @@ public static function getInvoices(
103101
}
104102

105103
/**
106-
* Get BitPay refund instance.
104+
* Request the last BitPay Invoice webhook to be resent.
107105
*
108-
* @return Refund
109-
*/
110-
public static function Refund(): Refund
111-
{
112-
return new Refund();
113-
}
114-
115-
/**
116-
* Create a BitPay refund.
106+
* @link https://bitpay.com/api/#rest-api-resources-invoices-request-a-webhook-to-be-resent
117107
*
118-
* @link https://bitpay.com/api/#rest-api-resources-invoices-refund-an-invoice
108+
* @param string $invoiceId The id of the invoice for which you want the last webhook to be resent.
119109
*
120-
* @param $invoice Invoice A BitPay invoice object for which a refund request should be made. Must have
121-
* been obtained using the merchant facade.
122-
* @param $refundEmail string The email of the buyer to which the refund email will be sent
123-
* @param $amount float The amount of money to refund. If zero then a request for 100% of the invoice
124-
* value is created.
125-
* @param $currency string The three digit currency code specifying the exchange rate to use when
126-
* calculating the refund bitcoin amount. If this value is "BTC" then no exchange rate
127-
* calculation is performed.
128-
*
129-
* @return bool True if the refund was successfully created, false otherwise.
130-
* @throws BitPayException BitPayException class
110+
* @return bool True if the webhook has been resent for the current invoice status, false otherwise.
111+
* @throws \BitPaySDK\Exceptions\BitPayException BitPayException class
131112
*/
132-
public static function createRefund(
133-
Invoice $invoice,
134-
string $refundEmail,
135-
float $amount,
136-
string $currency
137-
): bool {
138-
return (new self())->client->createRefund($invoice, $refundEmail, $amount, $currency);
139-
}
140-
141-
/**
142-
* Retrieve all refund requests on a BitPay invoice.
143-
*
144-
* @link https://bitpay.com/api/#rest-api-resources-invoices-retrieve-all-refund-requests-on-an-invoice
145-
*
146-
* @param $invoice Invoice The BitPay invoice having the associated refunds.
147-
*
148-
* @return Refund[] An array of BitPay refund object with the associated Refund object updated.
149-
* @throws BitPayException BitPayException class
150-
*/
151-
public static function getRefunds(Invoice $invoice): array
113+
public static function requestInvoiceWebhook(string $invoiceId): bool
152114
{
153-
return (new self())->client->getRefunds($invoice);
115+
return (new self())->client->requestInvoiceNotification($invoiceId);
154116
}
155-
156-
/**
157-
* Retrieve a previously made refund request on a BitPay invoice.
158-
*
159-
* @link https://bitpay.com/api/#rest-api-resources-invoices-retrieve-a-refund-request
160-
*
161-
* @param $invoice Invoice The BitPay invoice having the associated refund.
162-
* @param $refundId string The refund id for the refund to be updated with new status.
163-
*
164-
* @return Refund A BitPay refund object with the associated Refund object updated.
165-
* @throws BitPayException BitPayException class
166-
*/
167-
public static function getRefund(Invoice $invoice, string $refundId): Refund
168-
{
169-
return (new self())->client->getRefund($invoice, $refundId);
170-
}
171-
172-
/**
173-
* Cancel a previously submitted refund request on a BitPay invoice.
174-
*
175-
* @link https://bitpay.com/api/#rest-api-resources-invoices-cancel-a-refund-request
176-
*
177-
* @param $invoiceId string The refund id for the refund to be canceled.
178-
* @param $refund Refund The BitPay invoice having the associated refund to be canceled.
179-
* Must have been obtained using the merchant facade.
180-
*
181-
* @return bool True if the refund was successfully canceled, false otherwise.
182-
* @throws RefundCancellationException RefundCancellationException class
183-
*/
184-
public static function cancelRefund(string $invoiceId, Refund $refund): bool
185-
{
186-
return (new self())->client->cancelRefund($invoiceId, $refund);
187-
}
188-
189-
// TODO: Awaiting upstream merge: https://github.com/bitpay/php-bitpay-client-v2/pull/69
190-
// /**
191-
// * Request the last BitPay Invoice webhook to be resent.
192-
// *
193-
// * @link https://bitpay.com/api/#rest-api-resources-invoices-request-a-webhook-to-be-resent
194-
// *
195-
// * @param string $invoiceId The id of the invoice for which you want the last webhook to be resent.
196-
// * @param string $invoiceToken The resource token for the `invoiceId` you want the webhook to be resent.
197-
// *
198-
// * @return bool True if the webhook has been resent for the current invoice status, false otherwise.
199-
// * @throws \BitPaySDK\Exceptions\BitPayException BitPayException class
200-
// */
201-
// public static function requestInvoiceWebhook(string $invoiceId, string $invoiceToken): bool
202-
// {
203-
// return (new self())->client->requestInvoiceWebhook($invoiceId, $invoiceToken);
204-
// }
205117
}

src/Actions/ManageRefunds.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Vrajroham\LaravelBitpay\Actions;
4+
5+
use BitPaySDK\Exceptions\BitPayException;
6+
use BitPaySDK\Exceptions\RefundCancellationException;
7+
use BitPaySDK\Model\Invoice\Invoice;
8+
use BitPaySDK\Model\Invoice\Refund;
9+
10+
11+
trait ManageRefunds
12+
{
13+
14+
/**
15+
* Get BitPay refund instance.
16+
*
17+
* @return Refund
18+
*/
19+
public static function Refund(): Refund
20+
{
21+
return new Refund();
22+
}
23+
24+
/**
25+
* Create a BitPay refund.
26+
*
27+
* @link https://bitpay.com/api/#rest-api-resources-invoices-refund-an-invoice
28+
*
29+
* @param $invoice Invoice A BitPay invoice object for which a refund request should be made. Must have
30+
* been obtained using the merchant facade.
31+
* @param $refundEmail string The email of the buyer to which the refund email will be sent
32+
* @param $amount float The amount of money to refund. If zero then a request for 100% of the invoice
33+
* value is created.
34+
* @param $currency string The three digit currency code specifying the exchange rate to use when
35+
* calculating the refund bitcoin amount. If this value is "BTC" then no exchange rate
36+
* calculation is performed.
37+
*
38+
* @return bool True if the refund was successfully created, false otherwise.
39+
* @throws BitPayException BitPayException class
40+
*/
41+
public static function createRefund(
42+
Invoice $invoice,
43+
string $refundEmail,
44+
float $amount,
45+
string $currency
46+
): bool {
47+
return (new self())->client->createRefund($invoice, $refundEmail, $amount, $currency);
48+
}
49+
50+
/**
51+
* Retrieve all refund requests on a BitPay invoice.
52+
*
53+
* @link https://bitpay.com/api/#rest-api-resources-invoices-retrieve-all-refund-requests-on-an-invoice
54+
*
55+
* @param $invoice Invoice The BitPay invoice having the associated refunds.
56+
*
57+
* @return Refund[] An array of BitPay refund object with the associated Refund object updated.
58+
* @throws BitPayException BitPayException class
59+
*/
60+
public static function getRefunds(Invoice $invoice): array
61+
{
62+
return (new self())->client->getRefunds($invoice);
63+
}
64+
65+
/**
66+
* Retrieve a previously made refund request on a BitPay invoice.
67+
*
68+
* @link https://bitpay.com/api/#rest-api-resources-invoices-retrieve-a-refund-request
69+
*
70+
* @param $invoice Invoice The BitPay invoice having the associated refund.
71+
* @param $refundId string The refund id for the refund to be updated with new status.
72+
*
73+
* @return Refund A BitPay refund object with the associated Refund object updated.
74+
* @throws BitPayException BitPayException class
75+
*/
76+
public static function getRefund(Invoice $invoice, string $refundId): Refund
77+
{
78+
return (new self())->client->getRefund($invoice, $refundId);
79+
}
80+
81+
/**
82+
* Cancel a previously submitted refund request on a BitPay invoice.
83+
*
84+
* @link https://bitpay.com/api/#rest-api-resources-invoices-cancel-a-refund-request
85+
*
86+
* @param $invoiceId string The refund id for the refund to be canceled.
87+
* @param $refund Refund The BitPay invoice having the associated refund to be canceled.
88+
* Must have been obtained using the merchant facade.
89+
*
90+
* @return bool True if the refund was successfully canceled, false otherwise.
91+
* @throws RefundCancellationException RefundCancellationException class
92+
*/
93+
public static function cancelRefund(string $invoiceId, Refund $refund): bool
94+
{
95+
return (new self())->client->cancelRefund($invoiceId, $refund);
96+
}
97+
}

src/LaravelBitpay.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Vrajroham\LaravelBitpay\Actions\ManageLedgers;
1111
use Vrajroham\LaravelBitpay\Actions\ManagePayouts;
1212
use Vrajroham\LaravelBitpay\Actions\ManageRecipients;
13+
use Vrajroham\LaravelBitpay\Actions\ManageRefunds;
1314
use Vrajroham\LaravelBitpay\Actions\ManageSettlements;
1415
use Vrajroham\LaravelBitpay\Actions\ManageSubscriptions;
1516
use Vrajroham\LaravelBitpay\Traits\MakesHttpRequests;
@@ -25,6 +26,7 @@ class LaravelBitpay
2526
use ManageLedgers;
2627
use ManagePayouts;
2728
use ManageRecipients;
29+
use ManageRefunds;
2830
use ManageSettlements;
2931
use ManageSubscriptions;
3032

0 commit comments

Comments
 (0)