🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,81 @@
<?php
namespace Srmklive\PayPal\Tests\Feature;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
use Srmklive\PayPal\Tests\MockResponsePayloads;
class AdapterBillingPlansPricingHelpersTest extends TestCase
{
use MockClientClasses;
use MockResponsePayloads;
/** @var string */
protected static string $access_token = '';
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
$this->client->setClient(
$this->mock_http_client(
$this->mockAccessTokenResponse()
)
);
$response = $this->client->getAccessToken();
self::$access_token = $response['access_token'];
parent::setUp();
}
#[Test]
public function it_can_update_pricing_schemes_for_a_billing_plan(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client = $this->client->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addPricingScheme('DAY', 7, 0, true)
->addPricingScheme('MONTH', 1, 100);
$this->client->setClient(
$this->mock_http_client(false)
);
$response = $this->client->processBillingPlanPricingUpdates();
$this->assertEmpty($response);
}
#[Test]
public function it_can_set_custom_limits_when_listing_billing_plans(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client = $this->client->setPageSize(30)
->showTotals(true);
$this->client->setClient(
$this->mock_http_client(
$this->mockListPlansResponse()
)
);
$response = $this->client->setCurrentPage(1)->listPlans();
$this->assertNotEmpty($response);
$this->assertArrayHasKey('plans', $response);
}
}
@@ -0,0 +1,142 @@
<?php
namespace Srmklive\PayPal\Tests\Feature;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
class AdapterConfigTest extends TestCase
{
use MockClientClasses;
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
parent::setUp();
}
#[Test]
public function it_throws_exception_if_invalid_credentials_are_provided(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
$this->client = new PayPalClient([]);
}
#[Test]
public function it_throws_exception_if_invalid_mode_is_provided(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
$credentials = $this->getApiCredentials();
$credentials['mode'] = '';
$this->client = new PayPalClient($credentials);
}
#[Test]
public function it_throws_exception_if_empty_credentials_are_provided(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
$credentials = $this->getApiCredentials();
$credentials['sandbox'] = [];
$this->client = new PayPalClient($credentials);
}
#[Test]
public function it_throws_exception_if_credentials_items_are_not_provided(): void
{
$item = 'client_id';
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage("{$item} missing from the provided configuration. Please add your application {$item}.");
$credentials = $this->getApiCredentials();
$credentials['sandbox'][$item] = '';
$client = new PayPalClient($credentials);
}
#[Test]
public function it_can_take_valid_credentials_and_return_the_client_instance(): void
{
$this->assertInstanceOf(PayPalClient::class, $this->client);
}
#[Test]
public function it_throws_exception_if_invalid_credentials_are_provided_through_method(): void
{
$this->expectException(\RuntimeException::class);
$this->client->setApiCredentials([]);
}
#[Test]
public function it_returns_the_client_instance_if_valid_credentials_are_provided_through_method(): void
{
$this->client->setApiCredentials($this->getApiCredentials());
$this->assertInstanceOf(PayPalClient::class, $this->client);
}
#[Test]
public function it_throws_exception_if_invalid_currency_is_set(): void
{
$this->expectException(\RuntimeException::class);
$this->client->setCurrency('PKR');
$this->assertNotEquals('PKR', $this->client->getCurrency());
}
#[Test]
public function it_can_set_a_valid_currency(): void
{
$this->client->setCurrency('EUR');
$this->assertNotEmpty($this->client->getCurrency());
$this->assertEquals('EUR', $this->client->getCurrency());
}
#[Test]
public function it_can_set_a_request_header(): void
{
$this->client->setRequestHeader('Prefer', 'return=representation');
$this->assertNotEmpty($this->client->getRequestHeader('Prefer'));
$this->assertEquals($this->client->getRequestHeader('Prefer'), 'return=representation');
}
#[Test]
public function it_can_set_multiple_request_headers(): void
{
$this->client->setRequestHeaders([
'PayPal-Request-Id' => 'some-request-id',
'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
]);
$this->assertNotEmpty($this->client->getRequestHeader('PayPal-Request-Id'));
$this->assertEquals($this->client->getRequestHeader('PayPal-Partner-Attribution-Id'), 'some-attribution-id');
}
#[Test]
public function it_throws_exception_if_options_header_not_set(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode('0');
$this->expectExceptionMessage('Options header is not set.');
$this->client->getRequestHeader('Prefer');
}
}
@@ -0,0 +1,660 @@
<?php
namespace Srmklive\PayPal\Tests\Feature;
use Carbon\Carbon;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
use Srmklive\PayPal\Tests\MockResponsePayloads;
class AdapterCreateSubscriptionHelpersTest extends TestCase
{
use MockClientClasses;
use MockResponsePayloads;
/** @var string */
protected static string $access_token = '';
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
$this->client->setClient(
$this->mock_http_client(
$this->mockAccessTokenResponse()
)
);
$response = $this->client->getAccessToken();
self::$access_token = $response['access_token'];
parent::setUp();
}
#[Test]
public function it_can_create_a_monthly_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_a_daily_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addDailyPlan('Demo Plan', 'Demo Plan', 1.50);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_a_weekly_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addWeeklyPlan('Demo Plan', 'Demo Plan', 50);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_an_annual_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addAnnualPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_a_subscription_with_custom_defined_interval(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTH', 3);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_throws_exception_when_invalid_interval_is_provided_for_creating_a_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434');
$this->expectException(\RuntimeException::class);
$this->client = $this->client->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTHLY', 3);
}
#[Test]
public function it_throws_exception_when_get_error_for_creating_a_billing_plan(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansErrorResponse()
)
);
$this->expectException(\RuntimeException::class);
$this->client = $this->client->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
}
#[Test]
public function it_throws_exception_when_get_error_for_creating_a_product(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockGetCatalogProductsErrorResponse()
)
);
$this->expectException(\RuntimeException::class);
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
}
#[Test]
public function it_can_create_a_subscription_without_trial(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_a_subscription_by_existing_product_and_billing_plan(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_daily_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addDailyPlan('Demo Plan', 'Demo Plan', 1.50);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_weekly_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addWeeklyPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_monthly_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_an_annual_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addAnnualPlan('Demo Plan', 'Demo Plan', 100);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_subscription_with_custom_intervals(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTH', 3);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_add_setup_fees_when_creating_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$setup_fee = 9.99;
$this->client = $this->client->addSetupFee($setup_fee)
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_add_shipping_address_when_creating_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addShippingAddress('John Doe', 'House no. 123', 'Street 456', 'Test Area', 'Test Area', 10001, 'US')
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_add_custom_payment_failure_threshold_value_when_creating_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$threshold = 5;
$this->client = $this->client->addPaymentFailureThreshold($threshold)
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_set_tax_percentage_when_creating_subscription(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$percentage = 10;
$this->client = $this->client->addTaxes($percentage)
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
#[Test]
public function it_can_create_a_subscription_with_fixed_installments(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateCatalogProductsResponse()
)
);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePlansResponse()
)
);
$this->client = $this->client->addPlanTrialPricing('DAY', 7)
->addMonthlyPlan('Demo Plan', 'Demo Plan', 100, 12);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
}
@@ -0,0 +1,70 @@
<?php
namespace Feature;
namespace Srmklive\PayPal\Tests\Feature;
use Carbon\Carbon;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
use Srmklive\PayPal\Tests\MockRequestPayloads;
use Srmklive\PayPal\Tests\MockResponsePayloads;
class AdapterExperienceContextTest extends TestCase
{
use MockClientClasses;
use MockRequestPayloads;
use MockResponsePayloads;
/** @var string */
protected static string $access_token = '';
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
$this->client->setClient(
$this->mock_http_client(
$this->mockAccessTokenResponse()
)
);
$response = $this->client->getAccessToken();
self::$access_token = $response['access_token'];
parent::setUp();
}
#[Test]
public function it_can_set_payment_experience_context_before_performing_api_call(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->addDay()->toDateString();
$this->client = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setBrandName('Test Brand')
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');
$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);
$response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,75 @@
<?php
namespace Srmklive\PayPal\Tests\Feature;
use Carbon\Carbon;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
use Srmklive\PayPal\Tests\MockRequestPayloads;
use Srmklive\PayPal\Tests\MockResponsePayloads;
class AdapterOrdersHelperTest extends TestCase
{
use MockClientClasses;
use MockRequestPayloads;
use MockResponsePayloads;
/** @var string */
protected static string $access_token = '';
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
$this->client->setClient(
$this->mock_http_client(
$this->mockAccessTokenResponse()
)
);
$response = $this->client->getAccessToken();
self::$access_token = $response['access_token'];
parent::setUp();
}
#[Test]
public function it_can_confirm_payment_for_an_order(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$start_date = Carbon::now()->subDays(10)->toDateString();
$this->client = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setBrandName('Test Brand')
->setStoredPaymentSource(
'MERCHANT',
'RECURRING',
'SUBSEQUENT',
true,
'5TY05013RG002845M',
$start_date,
'Invoice-005',
'VISA'
);
$this->client->setClient(
$this->mock_http_client(
$this->mockConfirmOrderResponse()
)
);
$response = $this->client->setupOrderConfirmation('5O190127TN364715T', 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL');
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
}
}
@@ -0,0 +1,154 @@
<?php
namespace Srmklive\PayPal\Tests\Feature;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
use Srmklive\PayPal\Tests\MockClientClasses;
use Srmklive\PayPal\Tests\MockRequestPayloads;
use Srmklive\PayPal\Tests\MockResponsePayloads;
class AdapterPaymentMethodTokensHelpersTest extends TestCase
{
use MockClientClasses;
use MockRequestPayloads;
use MockResponsePayloads;
/** @var string */
protected static string $access_token = '';
/** @var PayPalClient */
protected PayPalClient $client;
protected function setUp(): void
{
$this->client = new PayPalClient($this->getApiCredentials());
$this->client->setClient(
$this->mock_http_client(
$this->mockAccessTokenResponse()
)
);
$response = $this->client->getAccessToken();
self::$access_token = $response['access_token'];
parent::setUp();
}
#[Test]
public function it_can_create_payment_token_from_a_vault_token(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePaymentMethodsTokenResponse()
)
);
$this->client = $this->client->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN')
->setCustomerSource('customer_4029352050');
$response = $this->client->sendPaymentMethodRequest();
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('customer', $response);
}
#[Test]
public function it_can_create_payment_source_from_a_vault_token(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePaymentSetupTokenResponse()
)
);
$this->client = $this->client->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN')
->setCustomerSource('customer_4029352050');
$response = $this->client->sendPaymentMethodRequest(true);
$this->assertArrayHasKey('payment_source', $response);
}
#[Test]
public function it_can_create_payment_source_from_a_credit_card(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$this->client->setClient(
$this->mock_http_client(
$this->mockCreatePaymentSetupTokenResponse()
)
);
$this->client = $this->client->setPaymentSourceCard($this->mockCreatePaymentSetupTokensParams()['payment_source']['card'])
->setCustomerSource('customer_4029352050');
$response = $this->client->sendPaymentMethodRequest(true);
$this->assertArrayHasKey('payment_source', $response);
}
#[Test]
public function it_can_create_payment_source_from_a_paypal_account(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$response_data = $this->mockCreatePaymentSetupTokenResponse();
$response_data['payment_source']['paypal'] = $this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal'];
unset($response_data['payment_source']['card']);
$this->client->setClient(
$this->mock_http_client($response_data)
);
$this->client = $this->client->setPaymentSourcePayPal($this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal'])
->setCustomerSource('customer_4029352050');
$response = $this->client->sendPaymentMethodRequest(true);
$this->assertArrayHasKey('payment_source', $response);
}
#[Test]
public function it_can_create_payment_source_from_a_venmo_account(): void
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);
$response_data = $this->mockCreatePaymentSetupTokenResponse();
$response_data['payment_source']['venmo'] = $this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal'];
unset($response_data['payment_source']['card']);
$this->client->setClient(
$this->mock_http_client($response_data)
);
$this->client = $this->client->setPaymentSourceVenmo($this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal'])
->setCustomerSource('customer_4029352050');
$response = $this->client->sendPaymentMethodRequest(true);
$this->assertArrayHasKey('payment_source', $response);
}
}