Beautiful Open-Source Form Builder
Enable coupons for self-hosted checkout
Julien Nahum579c03cbdbd3
diff --git a/api/app/Service/License/LicenseKeyService.php b/api/app/Service/License/LicenseKeyService.phpindex b4dff7a3f..b0b619195 100644--- a/api/app/Service/License/LicenseKeyService.php+++ b/api/app/Service/License/LicenseKeyService.php@@ -39,6 +39,7 @@ class LicenseKeyService]],'success_url' => config('services.license.checkout_success_url'),'cancel_url' => config('services.license.checkout_cancel_url'),+ 'allow_promotion_codes' => true,'billing_address_collection' => 'required','metadata' => ['type' => 'self_hosted_license',diff --git a/api/tests/Feature/SelfHosted/CloudLicenseApiTest.php b/api/tests/Feature/SelfHosted/CloudLicenseApiTest.phpindex 17436f538..b082339fa 100644--- a/api/tests/Feature/SelfHosted/CloudLicenseApiTest.php+++ b/api/tests/Feature/SelfHosted/CloudLicenseApiTest.php@@ -203,6 +203,46 @@ describe('POST /licenses/create', function () {$response->assertStatus(422)->assertJsonValidationErrors(['period']);});++ it('allows promotion codes on self-hosted license checkout sessions', function () {+ config([+ 'pricing.test.self_hosted.pricing.yearly' => 'price_self_hosted_yearly',+ ]);++ $stripeClient = new class () implements ClientInterface {+ public array $requests = [];++ public function request($method, $absUrl, $headers, $params, $hasFile, $apiMode = 'v1', $maxNetworkRetries = null)+ {+ $this->requests[] = compact('method', 'absUrl', 'headers', 'params', 'hasFile', 'apiMode');++ return [+ json_encode([+ 'id' => 'cs_self_hosted_coupon_test',+ 'object' => 'checkout.session',+ 'url' => 'https://checkout.stripe.test/session',+ ]),+ 200,+ [],+ ];+ }+ };+ ApiRequestor::setHttpClient($stripeClient);++ $response = $this->postJson('/licenses/create', [+ 'billingEmail' => '[email protected]',+ 'plan' => 'self_hosted',+ 'period' => 'yearly',+ ]);++ $response->assertSuccessful()+ ->assertJson([+ 'checkoutUrl' => 'https://checkout.stripe.test/session',+ 'sessionId' => 'cs_self_hosted_coupon_test',+ ]);++ expect($stripeClient->requests[0]['params']['allow_promotion_codes'])->toBe('true');+ });});describe('POST /licenses/portal', function () {