php - PayPal Chained payment using dynamic variables

639

I've got the PayPal chained payment working so that it works by inputting the receivers email addresses and the amount in quote marks in the code, but I cannot get this working dynamically using variables that have stored data from the query string.

I am using: https://github.com/braintreedev/paypal-adaptive-payments-wrapper-php as the framework behind the code below:

$price = $_GET['price'];
$projectid =$_GET['projid'];
$developeremail = $_GET['devemail'];

$devprice = $price * 0.9;

$paypal = new PayPal($config);

$result = $paypal->call(
  array(
'actionType'  => 'PAY',
'currencyCode'  => 'GBP',
'feesPayer'  => 'EACHRECEIVER',
'memo'  => 'Payment for project',

'cancelUrl' => 'cancel.php',
'returnUrl' => 'success.php',

'receiverList' => array(
  'receiver' => array(
      array(
      'amount'  => '100',
      'email'  => '[email protected]',
      'primary' => 'true',
      ),

      array(
      'amount' => '90',
      'email'  => '[email protected]',
    ),
  ),
),
  ),

  'Pay'
);

The code above is working but I want to swap the "[email protected]" email to the $developeremail variable and the amount to $devprice and the amount for "[email protected]" to be the value of $price but it doesn't process.

After doing some research it is because it is an associative array and the PHP engine cannot read variables, Do you guys know of any ways around this? I can't be the first person with this problem, right?

239

Answer

Solution:

What happens when you do this?

$price = $_GET['price'];
$projectid =$_GET['projid'];
$developeremail = $_GET['devemail'];

$devprice = $price * 0.9;

$paypal = new PayPal($config);

$result = $paypal->call(
  array(
'actionType'  => 'PAY',
'currencyCode'  => 'GBP',
'feesPayer'  => 'EACHRECEIVER',
'memo'  => 'Payment for project',

'cancelUrl' => 'cancel.php',
'returnUrl' => 'success.php',

'receiverList' => array(
  'receiver' => array(
      array(
      'amount'  => $price,
      'email'  => '[email protected]',
      'primary' => 'true',
      ),

      array(
      'amount' => $devprice,
      'email'  => $developeremail,
    ),
  ),
),
  ),

  'Pay'
);
313

Answer

Solution:

To find out what the problem is var_dump the $result, in my case the problem was that for a chained payment you need more than one secondary receiver, so i switched to parallel payment instead, thanks for all your help guys

People are also looking for solutions to the problem: php - Why would a variable change before its supposed to when a user clicks on post?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.