← All changes
|
src/Subscriptions/Factories/SubscriptionFactory.php
+15
-5
2.30.0
→
4.16.9
View file →
| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace Give\Subscriptions\Factories; |
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | use Give\Donations\Models\Donation; |
| 7 | +use Give\Donations\ValueObjects\DonationMode; | |
| 7 | 8 | use Give\Donations\ValueObjects\DonationStatus; |
| 8 | 9 | use Give\Donations\ValueObjects\DonationType; |
| 9 | 10 | use Give\Donors\Models\Donor; |
| 10 | 11 | use Give\Framework\Models\Factories\ModelFactory; |
| @@ -18,8 +19,9 @@ | ||
| 18 | 19 | |
| 19 | 20 | class SubscriptionFactory extends ModelFactory |
| 20 | 21 | { |
| 21 | 22 | /** |
| 23 | + * @since 4.11.0 add campaignId property | |
| 22 | 24 | * @since 2.24.0 add mode property |
| 23 | 25 | * @since 2.20.0 update default donorId to create factory |
| 24 | 26 | * @since 2.19.6 |
| 25 | 27 | * |
| @@ -40,34 +42,42 @@ | ||
| 40 | 42 | 'feeAmountRecovered' => new Money(0, 'USD'), |
| 41 | 43 | 'status' => SubscriptionStatus::PENDING(), |
| 42 | 44 | 'renewsAt' => give(GenerateNextRenewalForSubscription::class)(SubscriptionPeriod::MONTH(), $frequency), |
| 43 | 45 | 'donationFormId' => 1, |
| 46 | + 'campaignId' => 1, | |
| 44 | 47 | 'mode' => SubscriptionMode::TEST(), |
| 45 | 48 | ]; |
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | /** |
| 52 | + * @since 4.8.0 Respect subscription mode property | |
| 53 | + * @since 4.0.0 Add $donationAttributes parameter and merge it with the default attributes when creating a donation | |
| 49 | 54 | * @since 2.23.0 |
| 50 | 55 | * |
| 51 | 56 | * @return Subscription|Subscription[] |
| 52 | 57 | * @throws Exception |
| 53 | 58 | */ |
| 54 | - public function createWithDonation(array $attributes = []): Subscription | |
| 59 | + public function createWithDonation(array $subscriptionAttributes = [], array $donationAttributes = []) | |
| 55 | 60 | { |
| 56 | - $subscriptions = $this->create($attributes); | |
| 61 | + $subscriptions = $this->create($subscriptionAttributes); | |
| 57 | 62 | |
| 58 | - if ( $this->count === 1 ) { | |
| 63 | + if ($this->count === 1) { | |
| 59 | 64 | $subscriptions = [$subscriptions]; |
| 60 | 65 | } |
| 61 | 66 | |
| 62 | 67 | foreach ($subscriptions as $subscription) { |
| 63 | - $donation = Donation::factory()->create([ | |
| 68 | + $defaultDonationAttributes = [ | |
| 64 | 69 | 'amount' => $subscription->amount, |
| 65 | 70 | 'type' => DonationType::SUBSCRIPTION(), |
| 66 | 71 | 'status' => DonationStatus::COMPLETE(), |
| 67 | 72 | 'gatewayId' => $subscription->gatewayId, |
| 68 | 73 | 'subscriptionId' => $subscription->id, |
| 69 | - ]); | |
| 74 | + 'mode' => $subscription->mode->isTest() ? DonationMode::TEST() : DonationMode::LIVE(), | |
| 75 | + ]; | |
| 76 | + | |
| 77 | + $donation = Donation::factory()->create( | |
| 78 | + array_merge($defaultDonationAttributes, $donationAttributes) | |
| 79 | + ); | |
| 70 | 80 | |
| 71 | 81 | give()->subscriptions->updateLegacyParentPaymentId($subscription->id, $donation->id); |
| 72 | 82 | } |
| 73 | 83 | |