Problem/Motivation

Payments need a migration and payments require a gateway.

There was discussion (#15 - #22) to decide which payment gateway use so that migrated payments do not initiate a real transaction. It would be very bad to charge or refund customers twice. Also, the migrated payments should be historical and a reference only. The initial idea was to require (hook_requirements) so that a payment gateway exists before enabling commerce_migrate_ubercart, as well as, checking during the migration that it still exists. But that alone does not solve the problem of migrated transactions started a real transaction. Another idea was to create a 'migrated' payment gateway. That would have to be in another module so that commerce_migrate_ubercart could be uninstalled once the migration was done. After more thought on the topic, heddn suggested using the manual gateway and using entity_generate in the migration.

Payments and refunds are handled differently in Ubercart 6 and Commerce 2. In U6, a payment entry can be positive or negative. But in Commerce 2 refunds are tied to a particular payment.

Add refund to first payment that can cover the amount

Ubercart 6

ID Order no Amount
1 1 2000
2 1 -900
3 1 50
4 1 -800

Commerce 2 migrated

ID Order no Amount Refund
1 1 2000 1700
3 1 50 0

Spread refund across payments

Ubercart 6

ID Order no Amount
1 1 50
2 1 100
3 1 -100
4 1 30

Commerce 2 migrated

ID Order no Amount Refund
1 1 50 50
3 1 100 50
4 1 30 0

Proposed resolution

Use the manual payment gateway for all migrated transactions. This can be set as a constant in the migration yml.
Place all the logic to manipulating the refunds in prepareRow, well documented.
payment gateway migration with tests.
payment migration with tests.
Handbook Documentation

Remaining tasks

Handbook documentation
Handbook documentation for devs

User interface changes

N/A

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
#84 interdiff.txt1.08 KBquietone
#84 2887231-84.patch51.81 KBquietone
#81 interdiff.txt1.34 KBquietone
#81 2887231-81.patch51.81 KBquietone
#79 interdiff.txt3.19 KBquietone
#79 2887231-79.patch52.06 KBquietone
#77 interdiff.txt1.1 KBquietone
#77 2887231-77.patch49.4 KBquietone
#75 interdiff.txt705 bytesquietone
#75 2887231-75.patch48.93 KBquietone
#73 2887231-73.patch49 KBquietone
#72 2887231-72.patch38.49 KBquietone
#70 interdiff.txt6.78 KBquietone
#70 2887231-70.patch36.21 KBquietone
#67 interdiff.txt3.55 KBquietone
#67 2887231-67.patch35.03 KBquietone
#63 interdiff.txt4.21 KBquietone
#63 2887231-63.patch31.7 KBquietone
#61 interdiff.txt4.21 KBquietone
#61 2887231-61.patch4.21 KBquietone
#55 interdiff.txt6.2 KBquietone
#55 2887231-55.patch31.83 KBquietone
#54 interdiff.txt556 bytesquietone
#54 2887231-54.patch29.27 KBquietone
#52 interdiff.txt2.96 KBquietone
#52 2887231-52.patch29.3 KBquietone
#48 interdiff.txt10.76 KBquietone
#48 2887231-48.patch29.27 KBquietone
#45 2887231-46.patch27.7 KBquietone
#41 interdiff.txt2.44 KBquietone
#41 2887231-41.patch27.76 KBquietone
#38 interdiff.txt5.01 KBquietone
#38 2887231-38.patch27.64 KBquietone
#35 interdiff.txt12.05 KBquietone
#35 2887231-35.patch27.97 KBquietone
#30 2887231-30.patch29.09 KBwilleaton
#29 2887231-29.patch10.27 KBwilleaton
#16 2887231-16.patch24.4 KBquietone
#15 2887231-9.patch26.36 KBwilleaton
#8 2887231-8.patch25.63 KBquietone
#6 2887231-6.patch25.62 KBquietone
#4 2887231-4.patch25.71 KBquietone
#2 2887231-2.patch7.66 KBquietone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quietone created an issue. See original summary.

quietone’s picture

FileSize
7.66 KB

This patch is a work in progress. The source plugin and test are working. The migration and migration test are incomplete.

quietone’s picture

quietone’s picture

Status: Active » Needs review
FileSize
25.71 KB

Another step along the way. But all the basic functionality should be here.

This has the currency code, payment gateway and payment type set as constants in the migration. That needs to be fixed.

Status: Needs review » Needs work

The last submitted patch, 4: 2887231-4.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
25.62 KB

Hmm, worked for me. Nevertheless, found some things to tidy up.

Status: Needs review » Needs work

The last submitted patch, 6: 2887231-6.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
25.63 KB

Namespace error.

Status: Needs review » Needs work

The last submitted patch, 8: 2887231-8.patch, failed testing. View results

quietone’s picture

Still don't see it. The test passes for me from both the command line and the UI.

quietone’s picture

Status: Needs work » Postponed
Related issues: +#2888764: Process plugin for default store currency

This should be using the default currency process plugin. Postponing on #2888764: Process plugin for default store currency

willeaton’s picture

I think we can revisit this now right?

quietone’s picture

Status: Postponed » Needs work

OK, since this is U6 and we can get the currency using a variableGet.

Also, retesting.

quietone’s picture

Issue tags: +Needs reroll
willeaton’s picture

Issue tags: -Needs reroll
FileSize
26.36 KB

Hi, I haven't improved the functionality much, but I've rebuilt the patch to work with the latest dev version of commerce_migrate. I've adjusted the file locations based on the new structure, and changed the currency from fixed to a variable_get similar to the order_product migrate.
Note that this still needs work...

- If you don't have a payment gateway set up, it doesn't import, right now it throws the following error:

Drupal\Core\Entity\EntityMalformedException: Required payment field "payment_gateway" is empty. in Drupal\commerce_payment\Entity\Payment->preSave() (line 282 of /modules/contrib/commerce/modules/payment/src/Entity/Payment.php). [error]
Required payment field "payment_gateway" is empty. (/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:777)                                                                                                                [error]

So basically we need to decide what to do here, could we set up a dummy payment gateway temporarily and set all payments to a gateway of "Other"?

- there are some test things in the migrate template yml
- There are some fields commented out which I don't know if we need or what to do with
- There are references to "refunded_amount". In U6 you dont refund payment items, you create a new payment item with a negative value so this isn't relevant. Can we just remove it?

quietone’s picture

Status: Needs work » Needs review
FileSize
24.4 KB

Ran the tests on the latest patch. The errors were in the fixture.. Since I find them difficult to track and fix, I rerolled from the patch in #8 and did my best to get the changes in #9. Thanks willeaton for adding the currency change!

The commented out items in the migration yml are just identifying the fields that need more research to decide what to do for them.

Then I did some tweaks, like removed 'expected', from the variable names in the new test, added some comments etc.

The interdiff was double the size of the patch, so omitted here.

quietone’s picture

Good. tests pass. Still to do are the items raised in#15.

There are references to "refunded_amount". In U6 you dont refund payment items, you create a new payment item with a negative value so this isn't relevant. Can we just remove it?

So, all values that are <0 are refunds? Maybe open a new issue for migrating refunds and then we can remove the reference in the yml, with a comment.

willeaton’s picture

Correct, in the days of U6, refunds initiated from ubercart didn't exist. The payment module was more like a log so anything less than 0 is a refund, correct.

The most important thing right now to get this working is a decision on the payment gateway issue. Can we make the migrate module require an "other" type payment gateway on install or something? I don't see migrating payment gateways being feasible really

quietone’s picture

@willeaton, not sure how to process on that.

@mglaman, @heddn. what should we do about the payment gateway problem willeaton found in #15 and the suggestion on #18.

heddn’s picture

I think for the payment gateway question, I would suggest we add a hook_requirements stating you must configure a payment gateway before enabling the module. Then add an extra layer of protection by throwing an exception in the migration if the gateway was removed and no longer exists.

It still leaves a lingering question of what we want to do for these payments, since we don't want to errantly let someone refund the thing via their new payment gateway. Maybe we need to build a require a 'migrated' payment gateway (based on manual) that is hidden/disabled so no new payments can use it. This new module should retain the legacy payment gateway's 'name/title', in case we want to see how/where it was sourced from. This gateway shouldn't exist in commerce_migrate because we want to disable migrate later on. It could be a required contrib module. Don't know. I prefer a new gateway over manual, because the site could accept new manual payments later on and I wouldn't want to confuse those new payments with the earlier migrated payments.

heddn’s picture

  1. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Payment.php
    @@ -0,0 +1,97 @@
    +    // Ubercart 6 stores credit card information in a hash. Since this probably
    +    // isn't necessary so I removed it here.
    

    Comment suggestion: Ubercart 6 stores credit card information in a hash. Remove it.

  2. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Payment.php
    @@ -0,0 +1,97 @@
    +    unset($data['cc_data']);
    

    I don't see any examples of this in the source test data. Do we need to test that?

heddn’s picture

I was thinking about my response in #20. I think we can use the manual gateway. And extend/use entity_generate from migrate_plus to generate the manual payment_gateway in D8 based on the name of what it was in D6. This would allow us to import payments into a 'authorize.net' or 'paypal' manual gateway. If a site needed to accept real/actual manual payments, they could easily just build one itself.

heddn’s picture

Status: Needs review » Needs work

If we need to patch migrate_plus to support generation of config entities with entity_generate, we can do that.

willeaton’s picture

OK, so you are saying that we need to require the manual gateway module (is this a core or contrib module?) and thus with this we can import payments without actually processing them and match the single payment gateway to all payment lines?
In most projects I've worked on there are multiple payment gateways (uc_sermepa + uc_paypal), would it be possible to import multiple gateways and associate them on a per payment basis?

Checking the database model in D6, there is no relationship between gateways and payments, just "method" which we already match to "payment_method". Maybe, at least for D6, a single payment gateway would be fine, called say "Others", and we could simply import the methods as is. The methods I have on a site are:

Credit Card
paypal_ec
Other

heddn’s picture

@willeaton manual is part of commerce core.

willeaton’s picture

@heddn, how should I go about this? Set up the payment gateway in a preprocess of the payment migrate or create a new gateway migration which sets up manual gateways for each gateway previously installed?

heddn’s picture

re #26: I suggest using entity_generate from migrate_plus to build the gateway. If you need to patch the process plugin to get it working, coordinate with me. There's a couple issues in the queue that has aspirations and we could probably fit it into one of them. Hopefully entity_generate "Just Works (tm)"

willeaton’s picture

I'll work on this the next few days. I'll probably need some support on this though

willeaton’s picture

FileSize
10.27 KB

OK, here is my updated patch so far. Points done:

  • Written code to handle refunds (untested)
  • Gone through the lines and removed comments and lines we are not going to migrate
  • Lines are simply migrated to a manual payment gateway, there seems to be no way to migrate even the name of the previous gateway, or its comments

Points still left to do:

  • Set up the entity_generate to pre-create the payment gateways
  • Create multiple payment gateways for each found in D6
  • Test refund payments
willeaton’s picture

FileSize
29.09 KB

OK, here is a new updated patch. Points done:

  • Written code to handle refunds
  • Gone through the lines and removed comments and lines we are not going to migrate
  • Lines are simply migrated to a manual payment gateway using the same name as before, there seems to be no way to migrate its comments
  • Set up the entity_generate to pre-create the payment gateways (separate migration)
  • Create multiple payment gateways for each found in D6
  • Tested refund payments and they work but could fail quite easily with weird data

Points still left to do:

  • Create payment migrate tests

As far as Im concerned, this is a working migration now. Time to test. Could someone please help me write the tests?

willeaton’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: 2887231-30.patch, failed testing. View results

willeaton’s picture

Status: Needs work » Needs review

Not sure why it failed, seems to be an error with the test environment to me. Can anyone help so we can close this?

The last submitted patch, 29: 2887231-29.patch, failed testing. View results

quietone’s picture

FileSize
27.97 KB
12.05 KB

Only did coding standard changes, plus a file rename.

Status: Needs review » Needs work

The last submitted patch, 35: 2887231-35.patch, failed testing. View results

quietone’s picture

A bit of a review. I will work on these next.

  1. +++ b/modules/ubercart/migration_templates/d6_ubercart_order_payment.yml
    @@ -0,0 +1,32 @@
    +  payment_gateway: ¶
    

    trailing space

  2. +++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateways.yml
    @@ -0,0 +1,27 @@
    +id: d6_ubercart_payment_gateways
    +label: Ubercart payment gateways
    

    Use singular noun

  3. +++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateways.yml
    @@ -0,0 +1,27 @@
    +  plugin: ¶
    ...
    +    default_values: ¶
    ...
    +      payment_method_types: ¶
    

    trailing space

  4. +++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateways.yml
    @@ -0,0 +1,27 @@
    \ No newline at end of file
    

    no newline at end of file

  5. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,140 @@
    + *   id = "d6_ubercart_payment_receipts",
    

    make singular

  6. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,140 @@
    +    $fields = [
    

    Add the other properties in prepareRow etc here

  7. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Payment.php
    @@ -0,0 +1,60 @@
    + *   id = "d6_ubercart_payment_gateways",
    

    make singular

  8. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Payment.php
    @@ -0,0 +1,60 @@
    +      ->fields('upr', ['method']);
    

    This doesn't match fields method.

  9. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Payment.php
    @@ -0,0 +1,60 @@
    +  public function prepareRow(Row $row) {
    

    Can be removed.

  10. +++ b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/d6/PaymentTest.php
    @@ -0,0 +1,97 @@
    +    $tests[0]['expected_data'] = [
    

    Payment is only returning 'method', it needs to return all these fields.

quietone’s picture

FileSize
27.64 KB
5.01 KB

And fixes for those.

quietone’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 38: 2887231-38.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
27.76 KB
2.44 KB

Add requirement for migrate_plus to the tests.

Status: Needs review » Needs work

The last submitted patch, 41: 2887231-41.patch, failed testing. View results

quietone’s picture

--- /dev/null
+++ b/modules/ubercart/migration_templates/d6_ubercart_order_payment.yml

--- /dev/null
+++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateway.yml

Move to migrations directory

  1. +++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateway.yml
    @@ -0,0 +1,28 @@
    +  plugin: ¶
    ...
    +    default_values: ¶
    ...
    +      payment_method_types: ¶
    

    whitespace errors, space at end of line

  2. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,141 @@
    +      ->fields('upr', [
    

    This is all the fields in the tables so just use fields('upr')

Still to do:
Fix the failing test.
This creates two new migrations, d6_ubercart_order_payment, d6_ubercart_payment_gateway, but only one new migration test has been added.
The changes to the test fixture introduce a lots of uc_ variables. Do these need a migration.

quietone’s picture

  1. +++ b/modules/ubercart/migration_templates/d6_ubercart_order_payment.yml
    @@ -0,0 +1,32 @@
    +  type: 'constants/type'
    

    Missing constant entry in the source. What should the value of the constant be?

  2. +++ b/modules/ubercart/migration_templates/d6_ubercart_order_payment.yml
    @@ -0,0 +1,32 @@
    +    plugin: migration
    ...
    +    plugin: migration
    

    s/migration/migration_lookup/

  3. +++ b/modules/ubercart/migration_templates/d6_ubercart_payment_gateway.yml
    @@ -0,0 +1,28 @@
    +id: d6_ubercart_payment_gateway
    

    Does this really not need migration_dependencies?

  4. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,141 @@
    + * Provides migration source for orders.
    

    This is a source for payment_receipts. Really needs a paragraph explaining the how the payments are handled.

  5. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,141 @@
    +  public function prepareRow(Row $row) {
    

    In general, this needs more comments.

  6. +++ b/tests/src/Kernel/CommerceMigrateTestTrait.php
    @@ -257,6 +258,50 @@ trait CommerceMigrateTestTrait {
    +  private function assertPaymentEntity($id, $order_id, $type, $gateway_id, $payment_method, $amount, $amount_currency_code, $balance, $balance_currency_code, $label, $refunded_amount, $refunded_amount_currency_code) {
    

    Nit: Move this to alphabetical order.

quietone’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update
FileSize
27.7 KB

This should fix every in #43. Also #45.2 and #45.6

TODO:
#45.1, 3, 4, 5
Fix the failing test.
This creates two new migrations, d6_ubercart_order_payment, d6_ubercart_payment_gateway, but only one new migration test has been added.
The changes to the test fixture introduce a lots of uc_ variables. Do these need a migration?

The payment migration isn't straight forward, as explained to me by willeaton at DrupalCon. Therefor lets update the IS to explain a bit about that.

Status: Needs review » Needs work

The last submitted patch, 45: 2887231-46.patch, failed testing. View results

willeaton’s picture

Hi, I can write some documentation in about 12 hours, probably best that I do it. As for the tests I can probably provide the data in the fixture but I still need to learn how to write tests.... :-)

There is no need for any uc_variables added to the fixture to my knowledge, I haven't added these.

quietone’s picture

Status: Needs work » Needs review
FileSize
29.27 KB
10.76 KB
+++ b/modules/ubercart/migrations/d6_ubercart_payment_gateway.yml
@@ -0,0 +1,28 @@
+  configuration:

AFAIKT, the configuration is an array on the payment gateway entity. So, removing this.

Added a default type of 'check' to the payment gateway migration. But this needs to be double checked. What should the default gateway be?

MigratePaymentTest is currently failing because of the changes to the payment gateway source plugin. The payment migration uses a migration_lookup on the gateway migration.

Status: Needs review » Needs work

The last submitted patch, 48: 2887231-48.patch, failed testing. View results

willeaton’s picture

Hi!

AFAIKT, the configuration is an array on the payment gateway entity. So, removing this.

The thing is, if you remove this, where do we provide the payment gateway config? We are creating a new payment gateway for each payment type used in the source site, with specific configuration for these gateways to not appear in the checkout later on (internal only). The config I pass here are the values of the required fields you have to fill in when creating a payment gateway via the UI. Not sure how it could still work without these fields. Obviously I know very little about config_entity migrations so I may be wrong :-)

quietone’s picture

Just trying to understand the payment gateway migration part of this. Had a chat with willeaton and with joshmiller and did some manual testing. We want to create a payment ateway for each type of payment method in (uc_payment_receipts) using the manual plugin. The manual plugin is available by default. So, all we need to do is set the name and display name.

quietone’s picture

Status: Needs work » Needs review
FileSize
29.3 KB
2.96 KB

Restored the payment gateway source plugin to what is wasin #30. Then just a few tweaks to the payment migration and test to get the gateway and type correct.

Status: Needs review » Needs work

The last submitted patch, 52: 2887231-52.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
29.27 KB
556 bytes

Changed the source plugin but not the source plugin test. This should fix that.

quietone’s picture

FileSize
31.83 KB
6.2 KB
  1. +++ b/modules/ubercart/migrations/d6_ubercart_order_payment.yml
    @@ -0,0 +1,37 @@
    +    plugin: migration_lookup
    ...
    +    plugin: migration_lookup
    

    Add a skip row if empty

  2. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,132 @@
    +    $query->fields('uo', ['created', 'modified']);
    

    Not used

  3. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,132 @@
    +    $fields = [
    

    Add missing fields

  4. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,132 @@
    +    $data = unserialize($row->getSourceProperty('data'));
    

    Change to set source property data.

  5. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,132 @@
    +    $state = 'completed';
    

    Reworked the setting of state in the method to make it easier to read.

Added a source plugin test for OrderPayment, but it doesn't test all cases because the source plugins peeks at the destination to get payment information.

quietone’s picture

From the todo list in #45.

#44.1 - Removed. Get the type from the source.
Fix the failing test. - Migrate OrderPayment test fixed.
This creates two new migrations, d6_ubercart_order_payment, d6_ubercart_payment_gateway, but only one new migration test has been added. - PaymentGateway migration test added.
The changes to the test fixture introduce a lots of uc_ variables. Do these need a migration? - willeaton says they are not used in Commerce

That leaves :
#44.3 #44.4 and #44.5
And
The payment migration isn't straight forward, as explained to me by willeaton at DrupalCon. Therefor lets update the IS to explain a bit about that.

Those are about adding lots of comments and checking the migration dependencies (which look correct to me).

willeaton’s picture

My proposed documentation for this migration below. Please advise where best to add this, its not short.

This file handles the migration of the Drupal 6 Ubercart payment log. In Ubercart 2 of Drupal 6, the payment table is more like a log than anything else. There is a dedicated table with 1 row per payment. A payment can have a positive or negative value (refunds), and merely references a text value of the payment gateway. There is no attached functionality or relationships between a payment entry and the payment gateway.

In Drupal 8 commerce 2 a payment is directly associated to a payment gateway. There is one line per payment however refunds are associated to a specific payment. It is not possible for a single refund to have a higher value than that of a single payment. For example, you cannot have a 2 payments of 40€ totalling 80€ and associate 80€ of a refund to one of the payments. You would do a full refund of the two entries. This is the big difference between Ubercart 2 and Commerce 2.

Firstly, in order to set up the payment entries in Commerce 2, we have to create manual payment gateways. This is handled in a separate migrate (see d6_ubercart_payment_gateway). We have chosen to associate old payment entries with manual payment gateways, instead of associating them to the new payment modules for 2 reasons. Firstly we can’t guarantee that the module exists in Drupal 8 for the old payment gateway, nor that it has a migration prepared. Secondly, in Commerce 2, refunds associated to a real payment gateway might trigger an actual refund of the money. Imagine doing a migration and actually triggering a refund of all the money you ever charged your customers. The payment gateways are set to manual mode and are set to not appear in the checkout by default. The idea is that they exist for historic purposes, they are not intended for use after migration.

Once the payment gateways are migrated, and the orders and stores too, the payments are migrated. Its fairly straight forward, for every payment line in Ubercart 2, we add a payment line in Commerce 2. The complication comes when there is a refund. This migration plugin attempts to associate a refund to a previously migrated payment. This process is unconventional and not encouraged by the migrate team, but has been implemented for lack of a better solution. When the migration finds a refund, it will query the payments that have already been migrated for that order, find one that is larger than the refund value, and use that payment id as the destination for the refund instead of its own line.

Several things are assumed.
1. No order has a higher amount refunded than paid. This would have to be fixed manually.
2. No order has a refund before the first payment. This would have to be fixed manually.
3. No single refund is larger than all individual payments made. This would have to be fixed manually.

quietone’s picture

TL;DR all of that. I think two places, one in the code for devs and the other is a new page in Commerce Migrate for site admins. Do you have permission to make new pages?

quietone’s picture

@willeaton, thanks for the documentation! I did some wording tweaks and made a summary at the top, for those people only wanting to know the results, and then a details section.

heddn’s picture

Status: Needs review » Needs work

Looking really good. Just a couple small nits. Plus, it looks like we want an IS update? Which would help, since this has gone a couple directions.

Plus, we should add some developer docs as per #58.

  1. +++ b/modules/ubercart/migrations/d6_ubercart_order_payment.yml
    @@ -0,0 +1,45 @@
    +  # typ payment_manuak
    +  #payment_gateway - test /test2
    

    Copy/pasta

  2. +++ b/modules/ubercart/migrations/d6_ubercart_payment_gateway.yml
    @@ -0,0 +1,18 @@
    +  plugin:
    +    plugin: default_value
    +    default_value: manual
    

    static values in source would be more clear that there isn't any source for this.

  3. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,125 @@
    +    // If this is a refund we need ot attach it to a payment.
    

    ot = to.

  4. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,125 @@
    +      // Take first payment and see if its a positive amount.
    

    Nit: it is or it's.

  5. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,125 @@
    +      // Final check that it is a positive amount otherwise fail.
    

    Finally, check that is...

quietone’s picture

Status: Needs work » Needs review
FileSize
4.21 KB
4.21 KB

1-5 fixed.

Status: Needs review » Needs work

The last submitted patch, 61: 2887231-61.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
31.7 KB
4.21 KB

Oops. Ignore #61.

quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Status: Needs review » Needs work
  1. +++ b/modules/ubercart/src/Plugin/migrate/source/d6/OrderPayment.php
    @@ -0,0 +1,125 @@
    +      // Finally, check that it is a positive amount otherwise fail.
    +      if ($payment->getAmount() > 0) {
    ...
    +        $refund_amount = $row->getSourceProperty('amount');
    

    As far as I can tell this only checks against the first non negative payment. Shouldn't it check others if this one fails?

  2. +++ b/modules/ubercart/tests/fixtures/uc6.php
    @@ -22827,6 +22985,29 @@ $connection->schema()->createTable('uc_payment_receipts', array(
    +$connection->insert('uc_payment_receipts')
    

    There is only one payment in the source table, so we aren't really testing this migration.

quietone’s picture

FileSize
35.03 KB
3.55 KB

Start by adding some refunds to order #2.

quietone’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 67: 2887231-67.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
36.21 KB
6.78 KB

Fixed the getting of the payment amount value in the source plugin. Also, updated the test to include what I think are the correct migrated values.

Status: Needs review » Needs work

The last submitted patch, 70: 2887231-70.patch, failed testing. View results

quietone’s picture

FileSize
38.49 KB

Payments were not being saved because the type property in the yml was named after the constant value not the constant key. Then updated the tests to get everything passing. However, I'm not sure if the test values are correct. And I think the source plugin needs to search over all entries for a particular order.

quietone’s picture

Status: Needs work » Needs review
FileSize
49 KB

Should have done a reroll first.

This patch moves the work on refunds to the destination plugin because it needs to look at the already migrated payments to determine which ones to update with refunds. Refunds can now be spread across more than one payment. Another order was added that refunds more than the product amount. All refunds will add a message to the message table. A typical refund will have a simple 'Refund row' in the message table. If the refund amount is greater than the payment the message is 'Refund exceeds payment'.

Status: Needs review » Needs work

The last submitted patch, 73: 2887231-73.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Status: Needs work » Needs review
FileSize
48.93 KB
705 bytes

Yes, the source plugin changed so the test needs to be updated.

heddn’s picture

Status: Needs review » Needs work
  1. --- /dev/null
    +++ b/modules/ubercart/migrations/d6_ubercart_payment.yml
    
    @@ -0,0 +1,42 @@
    +  constants:
    +    type: payment_manual
    
    --- /dev/null
    +++ b/modules/ubercart/migrations/d6_ubercart_payment_gateway.yml
    
    @@ -0,0 +1,18 @@
    +  id:
    +    plugin: machine_name
    +    source: method
    

    This doesn't seem to match. Is it supposed to? I'd expect the type to be the same for the payment and for the payment gateway. Maybe it shouldn't?

  2. +++ b/modules/ubercart/src/Plugin/migrate/destination/d6/CommercePayment.php
    @@ -0,0 +1,142 @@
    +   * Builds an user entity destination.
    

    Copy/pasta.

  3. +++ b/modules/ubercart/src/Plugin/migrate/destination/d6/CommercePayment.php
    @@ -0,0 +1,142 @@
    +          $diff = Calculator::subtract($paid_amount, $total_refund_amount);
    

    This depends on commerce_payment module. Do we need to add that to the list of requirements in .info.yml or should we somehow do a check if the payment module is enabled before installing this config.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
FileSize
49.4 KB
1.1 KB

1. Yea, I haven't fully understood how that field is determined. Here it seems to be the plugin name 'manual' prefixed with 'payment' but for the demo site is it 'default_payment' even though the plugin is also manual.
2. Fixed.
3. Added commerce price to info.yml. It seems the simplest.

heddn’s picture

Status: Needs review » Needs work

I just thought of another option. Rather than doing the info.yml entry, what if you put it into optional config and did something like what is discussed in http://lightning.acquia.com/blog/optional-config-weirdness-drupal-8. And find a stable config dependency in payment you can depend upon.

quietone’s picture

Status: Needs work » Needs review
FileSize
52.06 KB
3.19 KB

Nice article, thanks. I didn't quite see how a dependency would prevent a migration from being discovered. So, I took the view of removing the migrations if the required modules were not installed. That can be done simply in plugins alter. Here is that approach.

heddn’s picture

Status: Needs review » Needs work

I feel bad about throwing this back on such small nits.

+++ b/modules/ubercart/tests/src/Kernel/PaymentTest.php
@@ -0,0 +1,68 @@
+      try {
+        // If this test passes, a PluginNotFoundException os thrown and we'll
+        // never reach fail().

s/os/is/

I think you can do $this->expectException(PluginNotFoundExceptionption::class);. See https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writ...

quietone’s picture

FileSize
51.81 KB
1.34 KB

Thats OK. Better to get it right the first time. expectException was not available, but setExpectedException is so I used that.

quietone’s picture

Status: Needs work » Needs review

Forgot to set to NR for testbot.

Status: Needs review » Needs work

The last submitted patch, 81: 2887231-81.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Status: Needs work » Needs review
FileSize
51.81 KB
1.08 KB

Test class had the wrong name. And added a type hint.

  • heddn committed da0e66e on 8.x-2.x authored by quietone
    Issue #2887231 by quietone, willeaton, heddn: [Ubercart] Migrate...
heddn’s picture

Status: Needs review » Fixed

All feedback addressed.

Status: Fixed » Closed (fixed)

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