stripe/stripe-php

1) PHPAssistsTest\Shared\Core\ThirdParty\Stripe\Entity\StripeAPITest::testCreatePriceA Undefined property: Stripe\Service\CoreServiceFactory::$price

juanma386 opened this issue · 3 comments

Describe the bug

Builded:

        $this->stripeAPI = new StripeAPI($this->testKey);
class StripeAPI {
    /**
     * The Stripe API key.
     */
    private ?string $stripeApiKey;

    /**
     * Instance of the Stripe Client.
     */
    private $stripe;

    /**
     * QueryMetadata instance for constructing queries.
     */
    private QueryMetadata $query;



    /**
     * StripeAPI constructor.
     *
     * Initializes the StripeAPI class with a Stripe API key.
     *
     * @param string|null $stripeApiKey The Stripe API key.
     *
     * @return void
     */
    public function __construct(?string $stripeApiKey) {
        $this->setApiKey((string) $stripeApiKey);
    }

    /**
     * Sets the Stripe API key.
     *
     * @param string|null $stripeApiKey The Stripe API key.
     *
     * @return void
     */
    public function setApiKey(?string $stripeApiKey) : void {
        $this->stripeApiKey = $stripeApiKey;
        $this->query = new QueryMetadata();
        $this->stripe = new \Stripe\StripeClient($this->stripeApiKey);
    }
    /**
     * Creates a new price for a product in Stripe.
     *
     * @param int $amount The amount of the price.
     * @param string $currency The currency of the price.
     * @param string $productId The ID of the product.
     *
     * @return mixed The created price object.
     */

    public function createPrice($amount, $currency, $productId) {
        return $this->stripe->price->create([
            'currency' => $currency,
            'unit_amount' => $amount,
            'product' => $productId,
        ]);
    }
    public function testCreatePriceA(): void
    {

        // Generate a random word as the product name
        $productName = $this->faker->word;
    
        // Create the product
        $product = $this->stripeAPI->createProduct($productName);
        // Assuming you are creating a price
        $price = $this->stripeAPI->createPrice(1000, "usd", $product->id);
    }

To Reproduce

1 Added this env, php8.3 testing
2 deployment

Expected behavior

For the testCreatePriceA:

  1. testCreatePriceA should:
    • Create a new price using the createPrice method of the StripeAPI object.
    • Expect the method to return an object representing a price in Stripe.
    • The assertInstanceOf assertion verifies that the returned object is an instance of the Stripe\Price class.
    • Expect the returned object to have the 'unit_amount' property with the provided price amount as an argument.
    • Expect the returned object to have the 'currency' property with the provided price currency as an argument.
    • Expect the returned object to have the 'product' property with the provided product ID as an argument.

These expectations ensure that the createPrice function in the StripeAPI class creates prices correctly in Stripe with the correct and required information, validating essential data for a price on the Stripe platform.

Code snippets

$  ./vendor/phpunit/phpunit/phpunit

Result:

    1) PHPAssistsTest\Shared\Core\ThirdParty\Stripe\Entity\StripeAPITest::testCreatePriceA
Undefined property: Stripe\Service\CoreServiceFactory::$price

/home/juanma/Documentos/Proyectos/Librarias/PHPAssists-Class/vendor/stripe/stripe-php/lib/Service/AbstractServiceFactory.php:65
/home/juanma/Documentos/Proyectos/Librarias/PHPAssists-Class/vendor/stripe/stripe-php/lib/StripeClient.php:99
/home/juanma/Documentos/Proyectos/Librarias/PHPAssists-Class/vendor/stripe/stripe-php/lib/StripeClient.php:90
/home/juanma/Documentos/Proyectos/Librarias/PHPAssists-Class/src/Shared/Core/ThirdParty/Stripe/Entity/StripeAPI.php:174
/home/juanma/Documentos/Proyectos/Librarias/PHPAssists-Class/test/Shared/Core/ThirdParty/Stripe/Entity/StripeAPITest.php:104


### OS

Debian 10

### PHP version

PHP8.3

### Library version

stripe/stripe-php: ^13.6

### API version

2023-10-16

### Additional context

**On testing present error with excecution unity testing php**

Error is tipyng is
return $this->stripe->prices->create([
not
return $this->stripe->price->create([

PHPUnit 9.6.15 by Sebastian Bergmann and contributors.

.............................................................
.... 65 / 94 ( 69%)
............................. 94 / 94 (100%)

Time: 00:05.933, Memory: 12.00 MB

OK (94 tests, 217 assertions)

Solved Type error on code