Skip to content

Commit dd6fced

Browse files
committed
Version 1.2.1: Subscription now creates Invoice with state "paid" and appropriate "amount"
1 parent aba1a05 commit dd6fced

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Mock of Stripe's HttpClient which can be used in testing purposes in order to test your code and not to perform actual HTTP requests",
44
"type": "library",
55
"license": "MIT",
6-
"version": "1.2.0",
6+
"version": "1.2.1",
77
"php": ">=7.4",
88
"autoload": {
99
"psr-4": {

src/Entity/Subscription.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public static function create(string $id, array $props = []): AbstractEntity
7777
);
7878
}
7979

80+
$currency = null;
81+
$amount = 0;
82+
8083
if (array_key_exists('items', $props)) {
8184
$items = new Collection();
8285

@@ -87,6 +90,8 @@ public static function create(string $id, array $props = []): AbstractEntity
8790
continue;
8891
}
8992

93+
$currency = $subscriptionItem->price->currency;
94+
$amount += (float) $subscriptionItem->price->unit_amount;
9095
$items->add($subscriptionItem);
9196
}
9297

@@ -110,6 +115,14 @@ public static function create(string $id, array $props = []): AbstractEntity
110115
$invoiceProps['customer'] = $props['customer'];
111116
}
112117

118+
if (array_key_exists('metadata', $props)) {
119+
$invoiceProps['metadata'] = $props['metadata'];
120+
}
121+
122+
$invoiceProps['paid'] = true;
123+
$invoiceProps['status'] = 'paid';
124+
$invoiceProps['currency'] = $currency;
125+
$invoiceProps['total'] = $amount;
113126
/** @var Invoice $invoice */
114127
$invoice = EntityManager::createEntity('invoice', $invoiceProps);
115128
$entity->props['latest_invoice'] = $invoice->id;

0 commit comments

Comments
 (0)