pronamic / wp-pronamic-pay-memberpress

MemberPress driver for the WordPress payment processing library.
http://www.wp-pay.org/extensions/memberpress/
4 stars 1 forks source link

Problem prices entered exclusive or inclusive tax #13

Closed remcotolsma closed 1 year ago

remcotolsma commented 1 year ago

With the inclusive tax setting the $memberpress_transaction->total value does not have the correct value at this point:

https://github.com/pronamic/wp-pronamic-pay-memberpress/blob/b5b6be195ea345698a97a895b25f6b67697ac9ef/src/Pronamic.php#L104-L114

Scherm­afbeelding 2023-06-19 om 16 36 14
object(MeprTransaction)[1997]
  protected 'rec' => 
    object(stdClass)[2086]
      public 'id' => string '22' (length=2)
      public 'amount' => string '54.98' (length=5)
      public 'total' => string '66.53' (length=5)
      public 'tax_amount' => string '11.55' (length=5)
      public 'tax_reversal_amount' => float 0
      public 'tax_rate' => int 21
      public 'tax_desc' => string 'VAT (Netherlands)' (length=17)
      public 'tax_class' => string 'vat' (length=3)
      public 'user_id' => string '1' (length=1)
      public 'product_id' => string '19' (length=2)
      public 'coupon_id' => string '20' (length=2)
      public 'trans_num' => string 'mp-txn-649067e1841ff' (length=20)
      public 'status' => string 'pending' (length=7)
      public 'txn_type' => string 'payment' (length=7)
      public 'gateway' => string 'rwi5gf-3ei' (length=10)
      public 'prorated' => string '0' (length=1)
      public 'created_at' => string '2023-06-19 14:36:17' (length=19)
      public 'expires_at' => string '2024-06-19 23:59:59' (length=19)
      public 'subscription_id' => string '22' (length=2)
      public 'corporate_account_id' => string '0' (length=1)
      public 'parent_transaction_id' => string '0' (length=1)
      public 'order_id' => string '0' (length=1)
      public 'tax_compound' => string '0' (length=1)
      public 'tax_shipping' => string '1' (length=1)
      public 'response' => null
  protected 'attrs' => 
    array (size=22)
      0 => string 'id' (length=2)
      1 => string 'amount' (length=6)
      2 => string 'total' (length=5)
      3 => string 'tax_amount' (length=10)
      4 => string 'tax_reversal_amount' (length=19)
      5 => string 'tax_rate' (length=8)
      6 => string 'tax_desc' (length=8)
      7 => string 'tax_class' (length=9)
      8 => string 'user_id' (length=7)
      9 => string 'product_id' (length=10)
      10 => string 'coupon_id' (length=9)
      11 => string 'trans_num' (length=9)
      12 => string 'status' (length=6)
      13 => string 'txn_type' (length=8)
      14 => string 'gateway' (length=7)
      15 => string 'prorated' (length=8)
      16 => string 'created_at' (length=10)
      17 => string 'expires_at' (length=10)
      18 => string 'subscription_id' (length=15)
      19 => string 'corporate_account_id' (length=20)
      20 => string 'parent_transaction_id' (length=21)
      21 => string 'order_id' (length=8)
  protected 'defaults' => null
  private 'object_type' (MeprBaseMetaModel) => string 'transaction' (length=11)
  private 'meta_table' (MeprBaseMetaModel) => string 'transaction_meta' (length=16)

The total property contains the "Sub-Total" value of 66.53 from the screenshot, the tax_amount value of 11.55 is a mystery to me.

Scherm­afbeelding 2023-06-19 om 16 42 13
remcotolsma commented 1 year ago

The client received the following response form support@memberpress.com:

Hi Renee.

After looking into everything you submitted, here's the response from one of our developers:

Without looking through all of their code to see what they are doing, it is hard to tell what could be wrong. The transaction created in MemberPress is correct, as you can see from the screenshot, so sometime after we create it, they alter it further before sending it to the payment processor.

The customer can loop us in with the Pronamic team so we can answer questions if we need to, but it's not something we can fix on our side."

Kind regards.

We just mailed support@memberpress.com the following message:

Hello Sinisa,

Earlier Renee from patterndrawing.online (CC) had contact with you about this. The Pronamic Pay plugin also contains a number of MemberPress gateways, including the popular Dutch payment method iDEAL. We extend your MeprBaseRealGateway class and implement the process_payment($txn) function. We expect the $txn parameter to contain the correct information for the payment. However, if amounts including VAT have been entered and this has been indicated in the settings, this is not always the case. As soon as a discount code is applied for the first payment, things go wrong. This is also easy to reproduce with your own MeprPayPalStandardGateway gateway. You probably end up not using the $txn->total value within the PayPal Standard gateway, so there won't be any problems. However, we must pass on the total to the popular Dutch iDEAL payment provider Mollie. You can debug by changing MeprPayPalStandardGateway.php like this:

  /**
   * Redirects the user to PayPal checkout
   *
   * @param MeprTransaction $txn
   * @throws MeprGatewayException
   * @throws Exception
   */
  public function process_payment_form($txn) {
    var_dump( $txn );exit;

See attachments for screenshots. As far as we can judge, developers like should be able to count on the correct transaction amounts/total in proces_payment_form($txn) and/or process_payment($txn) functions. Why does the transaction object not contain the correct amounts at this point, how should we or you solve this? You developers are also welcome to comment at https://github.com/pronamic/wp-pronamic-pay-memberpress/issues/13.

Remco Tolsma Pronamic


🖇️

memberpress-checkout-total-is-80 50 memberpress-code-vardump-exit-debug memberpress-checkout-submit-total-is-175 00

⏳ Waiting on response from MemberPress.

remcotolsma commented 1 year ago

No fix from MemberPress unfortunately:

We have passed your feedback on to the development team. They have logged it and will keep it in mind, but at this time have not road mapped any changes.

As I mentioned in our previous conversation, there is a way to get the information for the proper transaction amount through the trial amount on the subscription object. I recommend updating your code since it won't be changed in MemberPress for some time.

Solved this by merging the PR from @rvdsteege: