Charge end user
No edit summary
(Automatically adding template at the end of the page.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
If you run the standard authentication package, you will have your end users as SysUser objects.
If you run the standard authentication package, you will have your end users as SysUser objects.


Your service might cost some money to consume. To help you charge a SysUser an amount of money when he or she performs an action or wants to access a resource behind your paywall, we have added some streamlined functionality to get you going in minutes.
Your service might cost some money to consume. To help you charge a SysUser some money when he or she performs an action or wants to access a resource behind your paywall, we have added some streamlined functionality to get you going in minutes.


Add this method to SysUser in your model:
Add this method to SysUser in your model:
Line 9: Line 9:
Mark both methods with a tagged value: Eco.ExternalLateBound = Existence
Mark both methods with a tagged value: Eco.ExternalLateBound = Existence
[[File:2020-05-17 22h14 46.png|none|thumb|506x506px]]
[[File:2020-05-17 22h14 46.png|none|thumb|506x506px]]
When you call this method, the turnkey will do the following:
When you call this method, the Turnkey will do the following:
 
* It will post this data to [https://portal.mdriven.net https://portal.mdriven.net/] Consume which is a RestAllowed ViewModel in Portal. The root object is looked up as the TurnkeySite-object that exists in the portal based on its Guid. The Guid in your Turnkey system finds in the TurnkeySettings.xml file that the portal writes when you say SendSettings in the portal.  
It will post this data to [https://portal.mdriven.net https://portal.mdriven.net/] Consume which is a RestAllowed ViewModel in Portal. The root object is looked up as the TurnkeySite-object that exists in the portal based on its guid. The guid in your turnkey system finds in the TurnkeySettings.xml file that the portal writes when you say SendSettings in the portal.  
 
The key in SendSettings is:
The key in SendSettings is:
  <PortalGuid>a guid from the TurnkeySite object in portal</PortalGuid>
  <PortalGuid>a guid from the TurnkeySite object in portal</PortalGuid>
The settings file also includes the SharedSecret that you define on the login tab in the portal:
The settings file also includes the <code>SharedSecret</code> that you define on the login tab in the portal:
  <SharedSecret>a password shared between your site and portal</SharedSecret>
  <SharedSecret>a password shared between your site and portal</SharedSecret>
Your turnkey system will sign a UTC timestamp with this shared secret, and the portal will decrypt and verify that your system sent the Consume command and that it is not an old recorded Consume command.
Your Turnkey system will sign a UTC timestamp with this shared secret, and the portal will decrypt and verify that your system sent the Consume command and that it is not an old recorded Consume command.


An example of how to charge a SysUser:
An example of how to charge a SysUser:
Line 50: Line 48:


In a ViewModel, ensure that you have the following ViewModelColumns:
In a ViewModel, ensure that you have the following ViewModelColumns:
 
* PurchaseUrl:SysSingleton.oclsingleton.CurrentUser.GetPurchaseUrl(amount:Double; amountreadonly:Boolean; product:string; tag:String):String
PurchaseUrl:SysSingleton.oclsingleton.CurrentUser.GetPurchaseUrl(amount:Double; amountreadonly:Boolean; product:string; tag:String):String
* PayButtonText (string): This ViewModelColumn's value will be used by the PortalConsumer components Buy-Button
 
* ReturnFromPurchaseAction (action): This action will be executed when the user closes the purchase window; ex  vNewVar:=SysSingleton.oclsingleton.CurrentUser.Consume( 0 ,  'check' )  
PayButtonText (string): This ViewModelColumn's value will be used by the PortalConsumer components Buy-Button
* PortalConsumer: [Angular_Ext_Component=PortalConsumer] self->asset
 
ReturnFromPurchaseAction (action): This action will be executed when the user closes the purchase window; ex  vNewVar:=SysSingleton.oclsingleton.CurrentUser.Consume( 0 ,  'check' )  
 
PortalConsumer: [Angular_Ext_Component=PortalConsumer] self->asset
[[Category:MDriven Services]]
[[Category:MDriven Services]]
{{Edited|July|12|2024}}

Latest revision as of 15:28, 10 February 2024

If you run the standard authentication package, you will have your end users as SysUser objects.

Your service might cost some money to consume. To help you charge a SysUser some money when he or she performs an action or wants to access a resource behind your paywall, we have added some streamlined functionality to get you going in minutes.

Add this method to SysUser in your model:

Consume(amount:Double; message:String; tag:string):String

Also, add:

GetPurchaseUrl(amount:Double; amountreadonly:Boolean; product:string; tag:String):String  <- set this as IsQuery=true

Mark both methods with a tagged value: Eco.ExternalLateBound = Existence

2020-05-17 22h14 46.png

When you call this method, the Turnkey will do the following:

  • It will post this data to https://portal.mdriven.net/ Consume which is a RestAllowed ViewModel in Portal. The root object is looked up as the TurnkeySite-object that exists in the portal based on its Guid. The Guid in your Turnkey system finds in the TurnkeySettings.xml file that the portal writes when you say SendSettings in the portal.

The key in SendSettings is:

<PortalGuid>a guid from the TurnkeySite object in portal</PortalGuid>

The settings file also includes the SharedSecret that you define on the login tab in the portal:

<SharedSecret>a password shared between your site and portal</SharedSecret>

Your Turnkey system will sign a UTC timestamp with this shared secret, and the portal will decrypt and verify that your system sent the Consume command and that it is not an old recorded Consume command.

An example of how to charge a SysUser:

self.ConsumeRes:=SysSingleton.oclSingleton.CurrentUser
             .Consume(1.23,'You bought a magic strawberry','optional tag for you')

This call will return a JSON that looks like this:

{"Guid":"guid of the SysConsumer in portal",
 "ChangeTime":"2020-05-17T19:31:02.69",
"MCoinAccount_CurrentStanding":-2.46,
"LastTransactionTriedAmount":1.23,
"LastTransactionTriedMessage":"You bought a magic strawberry",
"LastTransactionTriedStatus":"Success",
"MCoinTransactions":[
  {"Guid":"a58753b9-2fe2-4fff-87ce-15294086fd9a",
   "MCoinAmount":-1.23,
   "Description":"Test20:06:40","ExitStanding":-2.46
  },
  {"Guid":"5d51e13b-c5cb-4329-aa72-de669c0d7109",
   "ChangeTime":"2020-05-17T19:31:02.69",
   "MCoinAmount":-1.23,
   "Description":"Test21:31:01","ExitStanding":-1.23
  }
]}

This JSON will contain the current transaction and the five earlier transactions for this SysUser - that has now become a SysConsumer in Portal. A SysConsumer has an account with MCoins/Euros that the consumer can top up.

You can decide to handle the returned JSON with Tajson Merge to build up a replica of the account information stored in the portal - but you do not have to.

Topping up the Consumer Account

To bring up a Purchase UI that allows your SysUser to top up the Account with Euros, do this:

Install the PortalConsumer component in EXT_Components

In a ViewModel, ensure that you have the following ViewModelColumns:

  • PurchaseUrl:SysSingleton.oclsingleton.CurrentUser.GetPurchaseUrl(amount:Double; amountreadonly:Boolean; product:string; tag:String):String
  • PayButtonText (string): This ViewModelColumn's value will be used by the PortalConsumer components Buy-Button
  • ReturnFromPurchaseAction (action): This action will be executed when the user closes the purchase window; ex vNewVar:=SysSingleton.oclsingleton.CurrentUser.Consume( 0 ,  'check' )
  • PortalConsumer: [Angular_Ext_Component=PortalConsumer] self->asset
This page was edited 96 days ago on 02/10/2024. What links here