From #2725247: Review gateway plugins, sort out what to do with \Drupal\sms\Plugin\SmsGatewayPluginInterface::balance(). It is not used by SMS Framework nor does it have test coverage.
Change name from balance() to getBalance() (similar to getDeliveryReports()) or getCreditsBalance() (preferred, similar to new reports). The 'get' prefix implies we need an external request, and should be used sparingly.
Make signature return float|NULL. NULL if unknown.
Add an annotation to gateway which determines whether the gateway supports balance inquiries.
Where can we use the balance system in SMS framework?
- Informational: In gateway list?, status page?
- Can we take action in any way based on known balance, or is it just informational?
- A more intelligent SMS routing system can use this information to shortlist gateways that are available. (from #3)
- A notification system can use this to inform the administrator that the available credits is running out (from #3)
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | gateway-balance-2798161-6-bf5749f.patch | 7.78 KB | dpi |
| #2 | gateway-balance-2798161.patch | 7.74 KB | dpi |
Comments
Comment #2
dpihttps://github.com/dpi/smsframework/pull/53
This patch changes:
Gateway::balance()toGateway::getCreditsBalance()getCreditsBalance()value from '0' to 'NULL'.schedule_awareandoutgoing_message_max_recipients.getCreditsBalanceto memory gateway.It does not include usage or testing of
Gateway::getCreditsBalance().Comment #3
almaudoh commentedThe following I can think of, amongst others:
Comment #4
dpiUpdated OP with others from #3
Comment #5
dpiUpdated PR addressing nits
Comment #6
dpiIncludes nits, merge with base
Comment #7
dpiKeep this issue around until some spinoff issues are created. I think some use cases in OP are worthy of first party support.
An internal mechanism to cache the current balance would be needed as well.
Comment #9
dpiCommitted, leaving open per #7
Comment #10
almaudoh commentedAn interesting problem just came up today: how to represent currencies when specifying the credit balance. I have developed gateway plugins for a number of providers from Europe, America and Asia, and the question of representing the currency of the credit balance keeps coming up. Some are not denominated, while some are.
If we are using
getCreditsBalance()for the purpose of display to the site admin, then we have to take question of currency into consideration.Comment #11
dpiIts funny, because I brought that up earlier in the year :D
The most "correct" way would be to depend on a currency module, and store the currency or credit system code (USD, AUD, Credit, Flooz, Beanz) alongside the balance value.
Or since this issue reformed the currency to always being a float, you can just assume there is only one currency/credit system per plugin, then add appropriate currency code symbols when displaying in UI.
Comment #12
dpiComment #13
dpiOpen to suggestions! :)
Then again this problem may be more trouble than we care to address.
Comment #14
almaudoh commentedSorry, I must have missed that. :)
Any of the options you presented in #11 is good enough - either a
getCreditsCurrency/setCreditsCurrencypair or acredit_balance_currencyannotation should be enough.We don't need to overwork it IMHO.
Comment #15
dpiIf we keep it the way it is, with a singular balance per plugin, then the currency unit doesnt really matter.
I think we would need to keep a record of the currency unit if there were multiple currencies per plugin. In which case we need to re-engineer what we have.
Comment #16
dpiIts been a while,
Wonder if abstracting currency related tasks to something like https://packagist.org/packages/commerceguys/intl makes sense...
Comment #17
dpi