Frage

I am creating a new debit for a customer using the following code. The problem is that when I check the balanced marketplace the customer has been debited twice.

<?php
Balanced\Settings::$api_key = "*********************";

$customer = \Balanced\Customer::get("/v1/customers/CU34xY6f9bKZzb0kjBxWTUjC");

$debit = $customer->debit('7000');
foreach ($debit as $key=> $value)  {  echo "$key : $value <br>";   }; 
?>

The first debit created shows up as the variable $debit returned by balanced, then there is a second one created and shown in the marketplace. If the code was running twice I would have expected to see the second one.

I have attempted the solution which has been mentioned for drupal running code twice

<?php 
  if (!function_exists('f')) { 
    function f() { 
      /* Code goes here */ 
      return $new_debit;
    }
  } 
$debit = f();
?>

The code is running as php in a block and activated on page load and I think the problem is related to blocks.

We solved the problem by putting the code is directly into the page body. It runs once and it does not matter if the teaser is set to hidden or not.

We do not intend to use blocks and when we have finished our testing we may be moving into a custom module. I am posting this in case anyone else has a similar problem and this helps them and also because I want to know why this is happening with blocks.

War es hilfreich?

Lösung

This problem is related to putting PHP code directly into a block.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top