Hi all,

I am working on a Xem cryptocurrency integration for Drupal Commerce. I have created a new payment method and it works fine.
I would like to make a better integration : at the moment "XEM" is not a currency for Drupal Commerce (https://www.drupal.org/sandbox/herve/2952914).

When i try to add a "custom currency" with the Back Office, the numeric code suggest me cryptocurrencies are not "currencies" for Drupal Commerce.

Is there something i have missed ? Or is this subject should become a new feature for Drupal Commerce ?

Regards,

Hervé

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

herve created an issue. See original summary.

mglaman’s picture

Just give it a fake code, no? Like 999. I don't believe we use that internally. It's just part of the currency data model.

herve’s picture

Tanks mglaman ! Yes, why not. Just wanted to be sure if there is not a "cleaner" way.
Just another question : is it possible in Commerce with Drupal 8 to have multiple currencies enabled and displayed at the same time on the cart, product page and so on ?

I remember there was a "Commerce multicurrency" for D7 version.

daveiano’s picture

Component: Developer experience » Price

I got a very similar issue when integration the TurlteCoin cryptocurrency into commerce. I also got the problem with the numeric code, but also the currency code "TRTL" does not follow the three characters standard, so I have to improvise here, too. Any plans, ideas or experience to support non-standard currency codes?

daveiano’s picture

Title: Non-ISO currencies » Non-ISO currencies - Cryptocurrency

Added "Cryptocurrency" to the title for better discoverability.

bojanz’s picture

We should simply drop the 3-letter requirement for currency codes. There is no need to enforce it.

Making numerical codes is harder cause we need to fix that in https://github.com/commerceguys/intl first.

daveiano’s picture

@bojanz Sounds good, but what validation would you suggest instead? As far as I can tell 4 letters are the longest currency codes of cryptocurrencies. So set the validation to 4 characters or something higher for maybe future currencies?

intl does its thing based on the numerical codes?

bojanz’s picture

Title: Non-ISO currencies - Cryptocurrency » Relax CurrencyForm validation to allow for cryptocurrencies
Category: Feature request » Task
Issue tags: -currencies, -cryptocurrency

Retitling.

We'll do the following:
1) Default the numeric code to "000", to allow the form to be submitted without modifying the value.
2) Allow 4-char currency codes.
3) Modify validation to only ensure that the format is uppercase letters.

bojanz’s picture

Status: Active » Needs review
FileSize
1.94 KB

Here's an initial patch.

Would be great to expand CurrencyTest to test this use case.

Can we think of a better validation error than "The currency code must consist only of uppercase letters." ?

daveiano’s picture

FileSize
3.33 KB

I've added the test with a test for adding a 'Test cryptocurrency' with currencyCode XXXX and the new default numericCode 000.

I don't know a better validation error, and I think it describes it already really well?

smccabe’s picture

Renamed version of #10 so tests can run.

Status: Needs review » Needs work

The last submitted patch, 11: 2952929-9-relax-currencyform-validation-11.patch, failed testing. View results

smccabe’s picture

Status: Needs work » Needs review
FileSize
4.11 KB

Test fails because 000 != '000', as an int 000 gets converted to 0 and thus fails.

Small update to string the value as well as slightly re-order tests to be more clear, so that save failures will show before the individual validation checks.

smccabe’s picture

Status: Needs review » Reviewed & tested by the community

I only made minor changes to the tests, so I think it is still ok for me to RTBC this one.

daveiano’s picture

Good catch with the numericCode, is looking good for me now!

daveiano’s picture

Any plans to get this into a release?

  • bojanz committed 8cc17c2 on 8.x-2.x authored by daveiano
    Issue #2952929 by smccabe, bojanz, daveiano: Relax CurrencyForm...
bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, everyone!

Status: Fixed » Closed (fixed)

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

bojanz’s picture

Reverted in https://git.drupalcode.org/project/commerce/commit/2c0d742, due to the conclusions in #3107288: Allow Currency codes which are more than 3 letters (we can't extend the price field storage to support 4-char currencies right now).

kopeboy’s picture

If this was reverted it should not be marked as "Closed (fixed)"?

I wanted to add that there is another problem (not just the 3 digit only currency code but also): the numeric code requirement => there are more cryptocurrencies than numbers still available and assigning this number is arbitrary.
I think we should allow an alternative field for at least the BIP44 coin types (see https://github.com/satoshilabs/slips/blob/master/slip-0044.md) that are commonly used by wallets to store/derive the keys for any supported network's currency (native token).

bojanz’s picture

Status: Closed (fixed) » Closed (won't fix)

Updating status to match reality. You are free to open a new feature request with a patch, but in general supporting cryptocurrencies is low on our list of priorities.