How to convert User points to vote ballots? I want to achieve the following functionality and I'm wondering if this could be possible:

For each purchase, one can gain userpoints (I can handle this using Rules).

Those userpoints will then be used to vote nominees. So if I have 1000 userpoints, i can use 300 for Candidate A, 500 for Candidate B, and and 200 for Candidate C. ( 1 userpoint = 1 ballot)

Can some give a hint/suggestion on how I could implement this. Workflow would be:


I select a candidate.
"Input" a vote amount.
Vote gets recorded.
Vote amount will be deducted from my userpoints.
Use the integration between the User Points module and the Rules module to "roll your own cookies", by writing some custom rules to transfer user points from one account to another.

As a sample, have a look at this rule, which is used in combination with voting of a node, whereas the author looses "-2" points, and the voter looses "-1" points:

{ "rules_votedown_question" : {
    "LABEL" : "votedown_question",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "answers" ],
    "REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
    "ON" : { "voting_rules_insert_node" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "answers_question" : "answers_question" } }
        }
      },
      { "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "-1" } }
    ],
    "DO" : [
      { "userpoints_action_grant_points" : {
          "user" : [ "node:author" ],
          "points" : "-2",
          "tid" : "0",
          "entity" : [ "" ],
          "description" : "Receive downvote to [node:type-name] \u0022[node:title]\u0022",
          "operation" : "QuestionDownvoteReceived",
          "reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
          "display" : "1",
          "moderate" : "default"
        }
      },
      { "userpoints_action_grant_points" : {
          "user" : [ "vote:user" ],
          "points" : "-1",
          "tid" : "0",
          "entity" : [ "" ],
          "description" : "Issue downvote to [node:type-name] \u0022[node:title]\u0022",
          "operation" : "QuestionDownvoteIssued",
          "reference" : "From uid=[node:author:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
          "display" : "1",
          "moderate" : "default"
        }
      }
    ]
  }
}


If you simply adapt the amount of points (-2 and -1) to something like (eg) +300 and -300, you've a prototype to transfer (300) user points from one user to another (eg Candidate A). Just repeat for Candidate B and C.

If you replace the Rules event by an event like "something is flagged" (created with the Flag module), a simple click could be used to indicate "I want to transfer some predefined (hardcoded) amount of user points of mine to this user). You could take this even a step further: since flags are fieldable, you could add a field to indicate the amount of points to be "moved", so that the user could enter "300" for Candidate A (instead of some hardcoded, fixed amount).

However, the above Rules example may need further refinements, e.g. if you want to ensure that after moving points from User A to User B, the remaining points for User A is not negative. Refer to "How to check whether one&#39;s current User Points are negative with the Rules module?" for details about how you can implement such refinement also.

PS: I'm assuming this question is about D7.