Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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é
Comment | File | Size | Author |
---|---|---|---|
#13 | 2952929-9-relax-currencyform-validation-13.patch | 4.11 KB | smccabe |
|
Comments
Comment #2
mglamanJust 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.
Comment #3
herve CreditAttribution: herve commentedTanks 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.
Comment #4
daveianoI 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?
Comment #5
daveianoAdded "Cryptocurrency" to the title for better discoverability.
Comment #6
bojanz CreditAttribution: bojanz at Centarro commentedWe 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.
Comment #7
daveiano@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?
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedRetitling.
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.
Comment #9
bojanz CreditAttribution: bojanz at Centarro commentedHere'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." ?
Comment #10
daveianoI've added the test with a test for adding a 'Test cryptocurrency' with
currencyCode XXXX
and the new defaultnumericCode 000
.I don't know a better validation error, and I think it describes it already really well?
Comment #11
smccabe CreditAttribution: smccabe as a volunteer and at Acro Commerce commentedRenamed version of #10 so tests can run.
Comment #13
smccabe CreditAttribution: smccabe as a volunteer and at Acro Commerce commentedTest 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.
Comment #14
smccabe CreditAttribution: smccabe as a volunteer and at Acro Commerce commentedI only made minor changes to the tests, so I think it is still ok for me to RTBC this one.
Comment #15
daveianoGood catch with the numericCode, is looking good for me now!
Comment #16
daveianoAny plans to get this into a release?
Comment #18
bojanz CreditAttribution: bojanz at Centarro commentedThanks, everyone!
Comment #20
bojanz CreditAttribution: bojanz at Centarro commentedReverted 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).
Comment #21
kopeboy CreditAttribution: kopeboy commentedIf 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).
Comment #22
bojanz CreditAttribution: bojanz commentedUpdating 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.