What's the reason to use

$payment_intent = json_decode(json_encode($payment_intent), TRUE);

in _commerce_stripe_pi_get_payment_intent()? Maybe we can improve this part?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sepgil created an issue. See original summary.

GoZ’s picture

This code is an easy way to convert an array to an object.

Suggestions are welcomed

klausi’s picture

Hm, but it looks like you want to convert to an array?
$array = (array) $yourObject; would do that.

sepgil’s picture

Status: Active » Needs review
FileSize
921 bytes

The results are objects containing other objects. $array = (array) $yourObject; casts only the top object but not the sub objects.

$payment_intent = json_decode(json_encode($payment_intent), TRUE); is probably the easiast way to convert everything into an array.

I attached a patch to add comments to those lines.

klausi’s picture

Title: json de- & encoding in _commerce_stripe_pi_get_payment_intent() » Document json de- & encoding in _commerce_stripe_pi_get_payment_intent()
Status: Needs review » Needs work

Ah, thanks for the explanation!

Super minor spacing issues:

  1. +++ b/commerce_stripe_pi.module
    @@ -2132,10 +2132,12 @@ function _commerce_stripe_pi_get_payment_intent(EntityMetadataWrapper $order_wra
    +    // Convert the object containing objects into a  recursive array.
    

    double space here

  2. +++ b/commerce_stripe_pi.module
    @@ -2132,10 +2132,12 @@ function _commerce_stripe_pi_get_payment_intent(EntityMetadataWrapper $order_wra
    +    // Convert the object containing objects into a  recursive array.
    

    and here

sepgil’s picture

Status: Needs work » Needs review
FileSize
919 bytes

You have eagle eyes :D

Added new patch.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Nice, thank you!

  • GoZ committed e66f229 on 7.x-1.x authored by sepgil
    Issue #3077686 by sepgil, klausi: Document json de-...
GoZ’s picture

Status: Reviewed & tested by the community » Fixed

Thanks making this module greater

Status: Fixed » Closed (fixed)

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