See #1268564: Support additional use cases.

I started to develop the first use case, which basically works but probably needs more work.

Features:

- Provides a virtual currency "Points", which *can* be used to sell products only for points
- An exchange rate per enabled currency, so that you an say that 1$ is worth 10 Userpoints
- A credit limit, which can allow your users to spend more points than they actually have
- The payment form basically displays an overview of your current points (see screenshot), how many you'll need and if you can buy this with points
- By setting the exchange rate to 0, you can disallow paying products for a given currency. This for example allows to have a shop that has products which can be paid (only) with points and others for which you need real money.

Todo's:

- Category integration, right now it only supports the default category.

Comments

liupascal’s picture

This use case was actually my first thought when i wanted to integrate a "userpoint" payment for drupal commerce.

The reason why i directly headed to a "line item" oriented solution rather than the payment system, is that (in my own use case, where I use points as "credit" or "royalties" which represents an in-site money account) users would rarely have enough points to afford a full product payment. It would have led to a solution where users would have to pay with userpoints AND complete their order balance with another payment solution.
I don't think this solution is very effective as it would probably bring confusion to users while checking out - definitively something any site owner dont want.

However, I understand that in some other use case this solution can be interesting.
- An exchange rate per enabled currency, so that you an say that 1$ is worth 10 Userpoints
I think that a solution using a custom CURRENCY TYPE would be more simple / effective, more easy to understand for the user(client) as well. Don't know if that's easily doable though...

berdir’s picture

Our use case for this system is similar to yours, a credit system based on userpoints for B2B sites. However, for these sites, users first buy a large hunk of points which they can then quickly access in single orders and being able to pay small amounts without high transaction costs.

So in most cases, this will be the only available payment provider (or maybe switched to credit card or something when there aren't enough points for a given order based on rules.)

- Yeah, the module also adds a new currency, which an be used. But after I implemented that, it looked kinda weird to me. Reasons behind exchange rate feature are:

- It allows you to have "normal" $ (or whatever you use) prices
- It allows to handle different currencies (1 $ is worth 5 points, 1€ 7 or so) in the same shop. Because they are not equal...
- It allows to work around the current "decimals problem". You could simply say that 1$ is worth 100 points. Then 1.85$ is 185 points.
- And especially without your discount use case, a single point might be worth much less than 1$ (because granting 0.01 points for writing a comment is just weird and not possible right now anyway)

Since this is something that should be supported equally across all modules, it might make sense for a common commerce_userpoints module that handles stuff like this.

andypost’s picture

Coming from #1297200-2: On-site user accounts and payments to/from the account
I guess this really useful and going to test this patch a bit latter

EndEd’s picture

Hi Im getting this notice when im trying to complete the checkout process without enough userpoints.

error icon 2 messages

Notice: Undefined index: payment_details in commerce_payment_pane_checkout_form_validate() (line 131 of C:\damp\www\es_gshop\sites\all\modules\commerce\modules\payment\includes\commerce_payment.checkout_pane.inc).
Not enough points.

Any hint?

tisbris’s picture

hi

i need some help with the settings for this module...

i managed to activate the payment module :O)
i managed to find the 'points' in the currency list and added this as default.
i managed to set the price for the product to x points

but at checkout i'm getting these:
•Notice: Undefined index: min_points in commerce_userpoints_payment_method_get_credit_limit() (line 101 of /home/www/mysite/sites/all/modules/commerce/modules/payment/modules/commerce_userpoints_payment_method.module).
•Notice: Undefined index: currencies in commerce_userpoints_payment_method_get_exchange_rate() (line 115 of /home/www/mysite/sites/all/modules/commerce/modules/payment/modules/commerce_userpoints_payment_method.module).

This order can not be paid with points.

Where are the settings for credit limit, exchange rate etc? - please

Thx
//Brian

rfay’s picture

Version: » 7.x-1.x-dev
rfay’s picture

@tisbris, #5, the workaround for this failure is that you have to visit the rule (admin/commerce/config/payment-methods/manage/commerce_payment_commerce_userpoints) and edit the action and save it. For some reason, $method_info['settings'] is not populated otherwise

    // Add the payment method specific form elements.
    $method_info = $order->payment_methods[$pane_form['payment_method']['#default_value']];
    $payment_method = commerce_payment_method_load($method_info['method_id']);
    $payment_method['settings'] = $method_info['settings'];

In this situation we end up with an empty array for the payment method settings.

rfay’s picture

This patch is the same thing as OP, except with a couple of text changes. Nothing relevant.

NOTE: This does *not* work with current Userpoints 7.x-2.x (Dev). It works only with Userpoints 7.x-1.0 (before #1258042: Revamp userpoints_userpointsapi() using an OOP approach similar to SelectQuery went in)

NOTE: Also see the required workaround in #7 - you must re-save the action in the rule.

andypost’s picture

Interesting is there protection in commerce to prevent paying by userpoints for userpoints increment...

rfay’s picture

#9 no, there isn't. Right now you'd have to have a payment method selection rule to prevent it.

PedroMiguel’s picture

For people getting "Strict Standards: Only variables should be passed by reference" using #8 patch, this code works for me (use an intermediate variable)

function commerce_userpoints_payment_method_get_exchange_rate($settings, $order) {
$inter = field_get_items('commerce_order', $order, 'commerce_order_total');
$order_total = array_shift($inter);
//  $order_total = array_shift(field_get_items('commerce_order', $order, 'commerce_order_total'));

  return $settings['currencies'][$order_total['currency_code']];
}

and

function commerce_userpoints_payment_method_get_required_points($settings, $order) {
	
  $requerido = field_get_items('commerce_order', $order, 'commerce_order_total');
  $order_total = array_shift($requerido);
 // $order_total = array_shift(field_get_items('commerce_order', $order, 'commerce_order_total'));

  $exchange_rate = commerce_userpoints_payment_method_get_exchange_rate($settings, $order);
  return ($order_total['amount'] / 100) * $exchange_rate;
}

Hope this can help someone

DEJU’s picture

I'm still receiving following message when there are not enough points available.

Notice: Undefined index: payment_details in commerce_payment_pane_checkout_form_validate() (line 150 of /var/www/mysite/sites/all/modules/commerce/modules/payment/includes/commerce_payment.checkout_pane.inc).
Not enough points.

Does anyone know how to fix this?

Thanks

spanac’s picture

Situation: exchange rate set to $1=100 points.
Problem: after user completes checkout, only 1 point will be deducted from his account.

Solution:
line 75 changed from:
'points' => ($charge['amount'] / 100) * -1,
to:
'points' => ($charge['amount'] / 100) * -100,

That will make point deduction work properly after user completes checkout, but only for exchange rate $1=100points.

mrfelton’s picture

Status: Needs review » Fixed

@liupascal just made me co-maintainer of this module (thanks). In order to get the ball rolling a little quicker on this one I've created a separate branch for this feature, 7.x-1.x-payment-method and committed the patch from #8.

I'm going to mark this issue as resolved. Lets follow up with any clean up patches in separate issues.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

a.milkovsky’s picture

StatusFileSize
new1.43 KB

PedroMiguel thanks for #11.
Fixed the issue with strict warning for me. I placed it in patch

a.milkovsky’s picture

Status: Closed (fixed) » Needs review

#11 and #16 needs review

mrfelton’s picture

Status: Needs review » Fixed

However, please dont hijack old threads. This thread was about creating a userpoints payment method, and that was committed months ago. The issue about strict warnings is a separate issue. In an case, I've committed the patch from #16. Thanks.

a.milkovsky’s picture

Sorry and thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gladiatorhl2’s picture

Issue summary: View changes

There is a question. How to disallow paying products when after paying the balance would be negative?

gladiatorhl2’s picture

Must a category be changed for another one?

gladiatorhl2’s picture

There is a big problem with this module. If there are several userpoint categories, the deduction is different every time. It depends on the history of deductions!