FLUX-SE / PayumStripe

Payum Stripe gateways (with SCA support)
MIT License
28 stars 15 forks source link

add null type hints #34

Open BlackbitDevs opened 1 year ago

BlackbitDevs commented 1 year ago

According to the latest API Stripe version now "payment_status" present not for all requests. When you try get data about payment POST /v1/payment_pages/cs_test_a1mwvpJk6c4mLg...... API will return data without "payment_status"

{
  "id": "ppage_xxxxxxxxx",
  "object": "checkout.session",
  "account_settings": {
    "account_id": "acct_xxxxxxxxxx",
    "assets": {
      "icon": null,
      "logo": null,
      "use_logo": false
    },
    "branding": {
      "background_color": null,
      "border_style": "default",
      "button_color": null,
      "font_family": "default"
    },
    "country": "DE",
    "display_name": "BLKBT",
    "privacy_policy_url": null,
    "specified_commercial_transactions_act_url": null,
    "statement_descriptor": "Blackbit",
    "support_email": null,
    "support_phone": "+49551506750",
    "support_url": null,
    "terms_of_service_url": null
  },
  "beta_versions": null,
  "billing_address_collection": null,
  "blocked_billing_address_countries": [
  ],
  "cancel_url": "http://xxxxx.con/cs/after-pay?payum_token=xxxxxxxxx",
  "card_brands": {
    "accel": false,
    "amex": true,
    "carnet": false,
    "cartes_bancaires": false,
    "diners": false,
    "discover": false,
    "eftpos_au": false,
    "elo": false,
    "girocard": false,
    "jcb": false,
    "mastercard": true,
    "nyce": false,
    "pulse": false,
    "star": false,
    "unionpay": true,
    "visa": true,
    "rupay": false
  },
  "client_reference_id": null,
  "consent": null,
  "consent_collection": null,
  "cross_sell_group": null,
  "currency": "eur",
  "custom_fields": [
  ],
  "custom_text": {
    "shipping_address": null,
    "submit": null
  },
  "customer": null,
  "customer_email": "xxxxxx@blackbit.de",
  "display_consent_collection_promotions": false,
  "eid": "NA",
  "email_collection": "always",
  "enabled_third_party_wallets": [
    {
      "id": "APPLE_PAY",
      "apple_pay": {
        "required_version": 2
      },
      "carousel_enabled": false,
      "enabled": true
    },
    {
      "id": "GOOGLE_PAY",
      "carousel_enabled": false,
      "enabled": true,
      "google_pay": {
        "id": "GOOGLE_PAY",
        "version_major": 2,
        "version_minor": 0
      }
    },
    {
      "id": "META_PAY",
      "carousel_enabled": false,
      "enabled": false
    },
    {
      "id": "LINK_BUTTON",
      "carousel_enabled": false,
      "enabled": true
    }
  ],
  "enforcement_mode": "open",
  "feature_flags": {
    "checkout_enable_apple_pay_tax_billing_address_collection_only_by_session": true,
    "checkout_passthrough_coupon": true,
    "checkout_stripepass_enabled": true,
    "checkout_pm_reuse_enabled": true,
    "checkout_lpm_adoption_lpm_popularity_ranking_experiment": true,
    "checkout_pay_button_copy_enabled": true,
    "checkout_send_expected_payment_method_type_param": true,
    "checkout_link_instant_debits_create_link_account_session_on_instantiation": true,
    "checkout_link_local_storage_login_enabled": true,
    "checkout_link_local_storage_login_on_custom_domains_enabled": true,
    "checkout_disable_email_overwriting": true,
    "checkout_phone_number_country_select_enabled": true,
    "checkout_id_bank_transfer_enable_mandiri": true,
    "checkout_validate_third_party_wallet_shipping_address": true,
    "checkout_jp_specified_commercial_transactions_act": true,
    "checkout_link_wallet_button": true,
    "checkout_payment_method_carousel_wallet": true
  },
  "geocoding": {
    "country_code": "DE",
    "region_name": null
  },
  "has_dynamic_tax_rates": false,
  "klarna_info": null,
  "konbini_confirmation_number": null,
  "line_item_group": {
    "currency": "eur",
    "discount_amounts": [
    ],
    "line_items": [
      {
        "id": "xxxxxxxxx",
        "object": "item",
        "adjustable_quantity": null,
        "cross_sell_from": null,
        "description": null,
        "discount_amounts": [
        ],
        "images": [
          "https://xxxxxxxxx"
        ],
        "name": "1x - test",
        "price": {
          "id": "price_xxxxxxxx",
          "object": "price",
          "active": false,
          "billing_scheme": "per_unit",
          "currency": "eur",
          "custom_unit_amount": null,
          "livemode": false,
          "product": {
            "id": "prod_xxxxxx",
            "object": "product",
            "active": false,
            "attributes": [
            ],
            "description": null,
            "images": [
              "https://placehold.it/400x300"
            ],
            "livemode": false,
            "name": "1x - test",
            "unit_label": null,
            "url": null
          },
          "recurring": null,
          "tax_behavior": "unspecified",
          "tiers_mode": null,
          "transform_quantity": null,
          "type": "one_time",
          "unit_amount": 154400,
          "unit_amount_decimal": "154400"
        },
        "quantity": 1,
        "subtotal": 154400,
        "tax_amounts": [
        ],
        "total": 154400,
        "unit_amount_override": null
      }
    ],
    "shipping_rate": null,
    "subtotal": 154400,
    "tax_amounts": [
    ],
    "total": 154400
  },
  "link_info": null,
  "link_settings": {
    "consumer_found": false
  },
  "livemode": false,
  "locale": "de",
  "mode": "payment",
  "ordered_payment_method_types": [
    "card"
  ],
  "payment_intent": {
    "id": "pi_xxxxxxxx",
    "object": "payment_intent",
    "amount": 154400,
    "amount_details": {
      "tip": {
      }
    },
    "automatic_payment_methods": null,
    "canceled_at": null,
    "cancellation_reason": null,
    "capture_method": "automatic",
    "client_secret": "pi_xxxxxxxxxx",
    "confirmation_method": "automatic",
    "created": 1679317213,
    "currency": "eur",
    "description": null,
    "last_payment_error": null,
    "livemode": false,
    "next_action": null,
    "payment_method": "pm_xxxxxxxxx",
    "payment_method_types": [
      "card"
    ],
    "processing": null,
    "receipt_email": null,
    "setup_future_usage": null,
    "shipping": null,
    "source": null,
    "status": "succeeded"
  },
  "payment_method_collection": "always",
  "payment_method_options": null,
  "payment_method_specs": [
    {
      "type": "card",
      "async": false,
      "fields": [
      ]
    }
  ],
  "payment_method_types": [
    "card"
  ],
  "phone_number_collection": {
    "enabled": false
  },
  "policies": null,
  "prefilled": null,
  "session_id": "cs_test_xxxxxxxx",
  "setup_future_usage": null,
  "setup_future_usage_for_payment_method_type": {
  },
  "setup_intent": null,
  "shipping_address_collection": null,
  "shipping_options": [
  ],
  "shipping_rate": null,
  "state": "succeeded",
  "submit_type": null,
  "subscription_data": null,
  "success_url": "http://xxxxxxxx.com/cs/after-pay?payum_token=xxxxxxxx",
  "tax_context": {
    "automatic_tax_address_source": null,
    "automatic_tax_enabled": false,
    "automatic_tax_error": null,
    "automatic_tax_exempt": "none",
    "customer_tax_country": null,
    "dynamic_tax_enabled": false,
    "has_maximum_tax_ids": false,
    "tax_id_collection_enabled": false
  },
  "tax_meta": {
    "computation_type": "manual",
    "customer_tax_exempt": "none",
    "error_reason": null,
    "status": "complete"
  },
  "url": null,
  "use_payment_methods": true,
  "utm_codes": null
}
codecov[bot] commented 1 year ago

Codecov Report

Merging #34 (cffe266) into master (cfe08dc) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##             master      #34   +/-   ##
=========================================
  Coverage     99.84%   99.85%           
- Complexity      427      428    +1     
=========================================
  Files           110      110           
  Lines          1321     1348   +27     
=========================================
+ Hits           1319     1346   +27     
  Misses            2        2           
Impacted Files Coverage Δ
src/Action/StatusSessionAction.php 100.00% <100.00%> (ø)

... and 19 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

Prometee commented 1 year ago

Hello @BlackbitDevs, thank you very much for this PR.

From what I can see in your Session object, the PaymentIntent is a full object instead of a simple ID, do you make a specific API call or this come from your shop Payment->details ?

Are you able to fix the build by removing the tests about the payment status ?

BlackbitDevs commented 1 year ago

Hello @BlackbitDevs, thank you very much for this PR.

From what I can see in your Session object, the PaymentIntent is a full object instead of a simple ID, do you make a specific API call or this come from your shop Payment->details ?

Hello @Prometee this API call came from shop (CoreShop bundle for Pimcore)

Are you able to fix the build by removing the tests about the payment status ?

Not sure. Can you suggest how to better do this?

Prometee commented 1 year ago

Hi @BlackbitDevs !

It's kind of weird the format you have in response, can you check your Stripe dashboard to see if you are using an old API version ? https://dashboard.stripe.com/developers (bottom of the page "API version".

Also can you check you are using the lastest version of this Payum lib ?

About the tests, one file is responsible to the change you made : https://github.com/FLUX-SE/PayumStripe/blob/master/tests/Action/StatusSessionActionTest.php. You can first read it to see what to change. I'm here to help you understand it.

BlackbitDevs commented 1 year ago

Hi @Prometee API version is [2022-11-15] Default Latest

payum/payum - versions : * 1.7.3

Prometee commented 1 year ago

After some digging, this behaviour is not possible unless Stripe has an issue with your account or something is altering the Stripe API response in your code.

Here is the Stripe Open API specifications for this field (those specs generate the stripe/stripe-php package):

https://raw.githubusercontent.com/stripe/openapi/1ab5ae5cab025b047c4f52707e141cb415ebace3/openapi/spec3.yaml

components:
  schemas:
    checkout.session:
      properties:
        payment_status:
          description: >-
            The payment status of the Checkout Session, one of `paid`, `unpaid`,
            or `no_payment_required`.

            You can use this value to decide when to fulfill your customer's
            order.
          enum:
            - no_payment_required
            - paid
            - unpaid
          type: string
      required:
        - payment_status

I git blame those line to see when the field has been introduced and it was done by this commit : https://github.com/stripe/openapi/commit/dd2806425f9d2212b6c1191ffb0f65b1af71b70c (Sep 2, 2020)

So clearly according to those specifications, the payment_status field can't be null at this point.

artyuum commented 1 year ago

After paying on Stripe and going back to the website, I had the following error:

FluxSE\PayumStripe\Action\StatusSessionAction::isCaptureStatus(): Argument #2 ($paymentStatus) must be of type string, null given, called in /var/www/html/sylius/ecommerce/vendor/flux-se/payum-stripe/src/Action/StatusSessionAction.php on line 28

This PR seemed to fix the issue but after applying the changes, it caused other problems. I don't think the changes in this PR are revelant as updating the plugin to the version 2.0.11 fixed my issue.