Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Metered billing? #173

Closed
CodeAndWeb opened this issue Mar 12, 2020 · 3 comments
Closed

Metered billing? #173

CodeAndWeb opened this issue Mar 12, 2020 · 3 comments

Comments

@CodeAndWeb
Copy link

How exactly should metered billing work?

I am writing a processor as you suggested but some things are quite strange. In my test I do the following:

subscribeToPlanAndProcessPayment() is a function that triggers a subscription

    Carbon::setTestNow('2020-04-01');
    $user->newSubscription('default', 'growth-v1')->create();
    ...simulate payment and mollie callback....
    Carbon::setTestNow('2020-04-10');
    $user->subscription()->swap('pro-v1');

handle() in my processor is called once with the following order Item:

  "owner_id" => 1
  "owner_type" => "App\Models\User"
  "process_at" => "2020-04-10 00:00:00"
  "currency" => "EUR"
  "unit_price" => 14900
  "quantity" => 1
  "tax_percentage" => "0.0000"
  "description" => "Pro plan, monthly payment"
  "orderable_id" => 1
  "orderable_type" => "Laravel\Cashier\Subscription"
  "updated_at" => "2020-04-10 00:00:00"
  "created_at" => "2020-04-10 00:00:00"
  "id" => 4

And the connected subscription:

"id" => 1
"name" => "default"
"plan" => "pro-v1"
"owner_type" => "App\Models\User"
"owner_id" => 1
"next_plan" => null
"quantity" => 1
"tax_percentage" => "0.0000"
"ends_at" => null
"trial_ends_at" => null
"cycle_started_at" => "2020-04-10 00:00:00"
"cycle_ends_at" => "2020-04-10 00:00:00"
"scheduled_order_item_id" => 4
"created_at" => "2020-04-01 00:00:00"
"updated_at" => "2020-04-10 00:00:00"

My questions are:

  1. Why is it only called once for the swap() and not for the initial payment?
  2. Why is cycle_started_at and cycle_ends_at both "2020-04-10 00:00:00" ? Should start and end not differ?
  3. How am I supposed to know for which period I have to get the metered billing details for?

Or am I doing it wong and I have to create my own order items before the processor is called?

@CodeAndWeb
Copy link
Author

CodeAndWeb commented Mar 13, 2020

More questions....

  1. Why am I not receiving the processor callback for the prorated / partially refunded first order?

invoice1.pdf
invoice2.pdf

Dates in this test are 2020-01-01 and 2020-01-10 (differing from the values in the first message)

@sandervanhooft
Copy link
Contributor

  1. It's not yet supported on the first payment. See How can i add an addOn to the firstpayment #177 .
  2. No. It will be set correctly once the payment has been processed and your webhook has been called. That happens before your customer is redirected back to your app from Mollie's checkout.
  3. Usually "usage up to the moment the Order is processed`" does the trick, so there's no attributes available on the preprocessor to check what cycle/period it's about. But I certainly can understand that there are other use cases that need more granular specificity than this. Interesting idea.
  4. Refund behaviour is on the backlog Add refund feature #148. I don't think the solution will involve the preprocessors firing automatically, will probably use an Event to listen for.

Some notes on testing/debugging:

  1. Are (other) webhook calls from Mollie reaching your app?
  2. Did you run cashier:run?
  3. Note that Mollie does not automatically update the status of mandated test payments. The status of mandated test payments can be manually set in the browser using the url provided by:
mollie()->payments()->get($paymentId)->_links->changePaymentState()

More info here.

@sandervanhooft
Copy link
Contributor

sandervanhooft commented Jun 11, 2020

Closing this for now, let me know if it should be reopened.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants