Giter Club home page Giter Club logo

Comments (8)

ppalmeida avatar ppalmeida commented on May 29, 2024 1

Sorry. I had to edit all my comment.

This is also was important:

Change...

new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']),

To...

new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'm']),

So, 'resettable_interval' => 'month' to 'resettable_interval' => 'm'

Now the method looks like this:

private function _createAPlan() {
    $plan = app('rinvex.subscriptions.plan')->create([
        'name' => 'Pro',
        'description' => 'Pro plan',
        'price' => 9.99,
        'signup_fee' => 0.00,
        'invoice_period' => 1,
        'invoice_interval' => 'm',
        'trial_period' => 15,
        'trial_interval' => 'd',
        'sort_order' => 1,
        'currency' => 'BRL',
    ]);

    $plan->features()->saveMany([
        new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]),
        new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
        new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'm']),
        new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
    ]);

    return $plan;
}

I will get my tests to green and back to you soon.

Thanks!!

from laravel-subscriptions.

ppalmeida avatar ppalmeida commented on May 29, 2024

Just to make sure this is not some dumb mistake made by me, this is the complete test method:

    /** @test */
    public function a_user_can_subscribe_to_a_plan()
    {
        // Create a plan and a user
        $user = factory(\App\User::class)->create([
            "email" => "[email protected]",
        ]);

        $plan = app('rinvex.subscriptions.plan')->create([
            'name' => 'Pro',
            'description' => 'Pro plan',
            'price' => 9.99,
            'invoice_period' => 1,
            'invoice_interval' => 'month',
            'trial_period' => 15,
            'trial_interval' => 'd',
            'sort_order' => 1,
            'currency' => 'USD',
        ]);

        $plan->features()->saveMany([
            new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]),
            new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
            new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']),
            new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
        ]);

        // User makes a subscription:
        $user->newSubscription("Pro", $plan);

        // Assertions:
        $this->assertEquals(1, $plan->subscriptions->count());
    }

from laravel-subscriptions.

noxify avatar noxify commented on May 29, 2024

Can you try:

[
            'name' => 'Pro',
            'description' => 'Pro plan',
            'price' => 9.99,
            'signup_fee' => 0.00,
            'invoice_period' => 1,
            'invoice_interval' => 'm',
            'trial_period' => 15,
            'trial_interval' => 'd',
            'sort_order' => 1,
            'currency' => 'USD',
]

instead of:

[
            'name' => 'Pro',
            'description' => 'Pro plan',
            'price' => 9.99,
            'invoice_period' => 1,
            'invoice_interval' => 'month',
            'trial_period' => 15,
            'trial_interval' => 'd',
            'sort_order' => 1,
            'currency' => 'USD',
]

invoice interval definition:
https://github.com/rinvex/subscriptions/blob/develop/src/Models/Plan.php#L188

signup fee definition:
https://github.com/rinvex/subscriptions/blob/develop/src/Models/Plan.php#L183

from laravel-subscriptions.

Omranic avatar Omranic commented on May 29, 2024

All interval fields are now string-based that accepts (hour, day, week, month) .. You should be able to use the latest release without any issues bf8b67b

from laravel-subscriptions.

ppalmeida avatar ppalmeida commented on May 29, 2024

Hi, @noxify

I got the latest version of dev-develop branch and now, when I run the code, it give these errors:

Illuminate\Support\MessageBag {#689
  #messages: array:2 [
    "trial_interval" => array:1 [
      0 => "The selected trial interval is invalid."
    ]
    "invoice_interval" => array:1 [
      0 => "The selected invoice interval is invalid."
    ]
  ]
  #format: ":message"
}

And with PlanFeature:

Illuminate\Support\MessageBag {#710
  #messages: array:1 [
    "resettable_interval" => array:1 [
      0 => "The selected resettable interval is invalid."
    ]
  ]
  #format: ":message"
}
array:8 [
  "plan_id" => "required|integer|exists:plans,id"
  "slug" => "required|alpha_dash|max:150|unique:plan_features,slug"
  "name" => "required|string|max:150"
  "description" => "nullable|string|max:10000"
  "value" => "required|string"
  "resettable_period" => "sometimes|integer"
  "resettable_interval" => "sometimes|string|in:hour,day,week,month"
  "sort_order" => "nullable|integer|max:10000000"
]

So, If I use "d" or "m" as periods, the rules are against it. Could you please, recheck them?

For example: in Plan Model (https://github.com/rinvex/subscriptions/blob/77e3f025915549b6329f6f0ffbc321a208678fa2/src/Models/Plan.php#L177) the rules are validating "month", "day" etc.

Thank you.

from laravel-subscriptions.

Omranic avatar Omranic commented on May 29, 2024

@ppalmeida you can NOT use short intervals any more. That said above already:

All interval fields are now string-based that accepts (hour, day, week, month) .. You should be able to use the latest release without any issues bf8b67b

So would you please try with the long intervals 🙂

from laravel-subscriptions.

ppalmeida avatar ppalmeida commented on May 29, 2024

Hi, @Omranic.

What you said above is very strange. Because I get this error from my tests:

Method Illuminate\Support\Carbon::addMs does not exist

And in the Period.php class I can see this line:

$this->interval = in_array($interval, ['d', 'w', 'm', 'y']) ? $interval : 'm';
if ($count > 0) {
    $this->period = $count;
}
$method = 'add'.ucfirst($this->interval).'s';

And this is exactly what I think is giving the erros. Because my factory looks like this:


$factory->define(Plan::class, function (Faker $faker) {
    return [
        'title' => 'Pro',
        'description' => "pro plan", // $faker->sentence($nbWords = 6, $variableNbWords = true),
        'price' => 9.99, // $faker->randomFloat($nbMaxDecimals = 2, $min = 9.0, $max = 50.0),
        'signup_fee' => 0.00,
        'invoice_period' => 1,
        'invoice_interval' => 'month',
        'trial_period' => 15,
        'trial_interval' => 'day',
        'sort_order' => 1,
        'currency' => 'BRL',
    ];
});

$factory->define(PlanFeature::class, function (Faker $faker) {
    return [
        'title' => 'listing_duration_days',
        'value' => 30,
        'sort_order' => 10,
        'resettable_period' => 1,
        'resettable_interval' => 'month'
    ];
});

And the errors still happening, because of this IF:
https://github.com/rinvex/subscriptions/blob/f3d51ff17639c45ee0864ea1158111335bc35d87/src/Services/Period.php#L58

from laravel-subscriptions.

Omranic avatar Omranic commented on May 29, 2024

Nice catch, thank you @ppalmeida 👍
That was a mistakenly leftover, and now fixed on 285f08e 😉

from laravel-subscriptions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.