subscribepro / subscribepro-magento2-ext

Subscribe Pro Magento 2 Integration Extension
MIT License
24 stars 22 forks source link

Update maskedCC in details of vault_payment_token when processing payment_profile.updated webhook. #268

Open chrismshea opened 8 months ago

chrismshea commented 8 months ago

Issue

  1. A credit card payment profile is created in Subscribe Pro a. This could be directly in Subscribe Pro b. This could be done via the Magento 2 integration
  2. The Merchant has Account Updater enabled on their Subscribe Pro environment, and all cards enrolled. (Account Updater is a tool used to retrieve changes to credit card from their issuer.)
  3. The credit card is updated, and there's a new card number and expiration date.
  4. The webhook payment_profile.updated is sent to Magento
  5. Magento processes the webhook and updates the Expiration Date only
  6. When customer checks out on Magento site or manages their payment profiles in Stored Payment Methods they see their old last four.

Expected Result

maskedCC and other updated fields (maskedCC, expirationDate, paymentToken) should be updated in the details section, and customer will see the correct last four of the card in Stored Payment Methods, and Checkout.

Steps to Reproduce

  1. Configure and Enable webhooks for Magento 2
  2. On Magento frontend create a customer
  3. In My Account > Stored Payment Methods Add New Card card_1
  4. Connect to your Magento MySql instance, and find the last created entry in the vault_payment_token table. SELECT * FROM vault_payment_token ORDER BY entity_id DESC LIMIT 1 \G; to get the id, etc.
    *************************** 1. row ***************************
          entity_id: 78
        customer_id: 26
        public_hash: 3e3c2d1d6c47bbc516b1a477a2b9be8571413e84562873bd0b5a2ffca7d628bb
    payment_method_code: subscribe_pro
               type: card
         created_at: 2023-12-21 14:10:56
         expires_at: 2026-12-01 00:00:00
      gateway_token: 7845336
            details: {"type":"MC","maskedCC":"0283","expirationDate":"11\/2026","paymentToken":"XkEfm01vLr8wmXHANyLecczqxP8"}
          is_active: 1
         is_visible: 1
  5. Now update it to change the expires_at and maskedCC and expireationDate fields in the details section
    UPDATE vault_payment_token SET expires_at = '2024-11-01 00:00:00', details = '{"type":"MC","maskedCC":"3333","expirationDate":"10\/2024","paymentToken":"XkEfm01vLr8wmXHANyLecczqxP8"}' WHERE entity_id = '78';

    Result

    *************************** 1. row ***************************
          entity_id: 78
        customer_id: 26
        public_hash: 3e3c2d1d6c47bbc516b1a477a2b9be8571413e84562873bd0b5a2ffca7d628bb
    payment_method_code: subscribe_pro
               type: card
         created_at: 2023-12-21 14:10:56
         expires_at: 2024-11-01 00:00:00
      gateway_token: 7845336
            details: {"type":"MC","maskedCC":"3333","expirationDate":"10/2024","paymentToken":"XkEfm01vLr8wmXHANyLecczqxP8"}
          is_active: 1
         is_visible: 1
  6. Find the Payment Profile in Subscribe Pro, and click the Save button. This will generate the payment_profile.updated webhook to be sent.
  7. Refresh the System > Webhook Event Log until you see that the webhook has been delivered.
  8. Return to Magento MySql, and select the last row. The expires_at and expirationDate in the details section should be returned to normal, but maskedCC is left in incorrect state.

I solved this in my dev env by:

Edit /Helper/Vault.php and added lines

diff --git a/Helper/Vault.php b/Helper/Vault.php
index 9b6d867..1025438 100644
--- a/Helper/Vault.php
+++ b/Helper/Vault.php
@@ -80,7 +80,9 @@ class Vault
     public function updateVault(PaymentTokenInterface $token, PaymentProfileInterface $profile)
     {
         $tokenDetails = $this->decodeDetails($token->getTokenDetails());
-        $tokenDetails['expirationDate'] = $profile->getCreditcardMonth() . '/' . $profile->getCreditcardYear();
+       $tokenDetails['expirationDate'] = $profile->getCreditcardMonth() . '/' . $profile->getCreditcardYear();
+       $tokenDetails['maskedCC'] = $profile->getCreditcardLastDigits();
+        $tokenDetails['paymentToken'] = $profile->getPaymentToken();

         unset($tokenDetails['state']);