CyberSource / cybersource-plugins-rest-salesforceb2ccommerce

Other
2 stars 2 forks source link

incorrect set/clear of variable #10

Closed moorena closed 2 months ago

moorena commented 5 months ago

Howdy,

When doing credit card authorization for orders, if you do a regular credit card order using Authorize only, and quickly do a second order, the wrong payment information will be written into the Salesforce order.

In the file: cartridges/int_cybs_sfra_base/cartridge/scripts/hooks/payment/processor/payments_credit.js

At line 264, we read/copy the value of session.privacy.encryptedDataGP

    gPayToken: session.privacy.encryptedDataGP

Then two things happen. The session value is set to blank ('') on line 267:

session.privacy.encryptedDataGP = '';

and we test the value we read on line 264 on line 284:

        if (card.gPayToken === null) {

Notice the difference ? We're setting it to blank, but testing against null. If we re-enter this code, the test on line 284 fails (blank is not null, so a different value is written to the paymentInstrument.paymentTransaction.custom.paymentDetails part of the order.

Other places in the code that read the session.privacy.encryptedDataGP value test it as: if (empty(session.privacy.encryptedDataGP))

I think the correct fix is to update line 284 https://github.com/CyberSource/cybersource-plugins-rest-salesforceb2ccommerce/blob/85de8efb3f900445c830c7a826a028725de28b3c/cartridges/int_cybs_sfra_base/cartridge/scripts/hooks/payment/processor/payments_credit.js#L284 to test if the card.gPayToken is empty and NOT test if it is null