1

I implemented the Drupal PayPal modules and it's working fine, now I want to add the PayPal adaptive payments chained which is used for send the amount for admin and agent.

So I configured the module commerce_paypal_chained. I don't know how to use it.

I got idea for PayPal adaptive payments getting from this node details https://www.drupal.org/node/2082691

Please help figure out this issue.

Thanks in advance

closed as unclear what you're asking by kiamlaluno Dec 29 '16 at 13:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to Drupal Answers! Please notice you are merely stating facts, without asking any explicit question. What exactly don't you understand? Saying I don't know how to use it is quite broad. You cannot expect users to tell you every detail about the module settings. If you have any specific question about a setting, that could be an acceptable question, but a question requiring users to guess what you don't understand is not. To make a culinary example, this question is similar to I don't understand how to make a cheesecake New York style. – kiamlaluno Dec 29 '16 at 13:06
0

Because chained payments are highly configurable and Drupal Commerce doesn't have the concept of multiple payment recipients baked into core, you have to define this in your own app using hook_commerce_paypal_apc_order_form_data_alter(), which the patch you reference defines. Without it, you'll only be sending payment information for 1 recipient.

You've got a lot of freedom as to how you handle this but here is an example using marketplace functionality:

  1. Install Commerce Marketplace.
  2. On the store entities that are set up, add a field for the store's owner to add their PayPal ID.
  3. Write a new custom module that implements hook_commerce_paypal_apc_order_form_data_alter(). See below.

hook_commerce_paypal_apc_order_form_data_alter() example for Commerce Marketplace:

function EXAMPLE_marketplace_commerce_paypal_apc_order_form_data_alter(&$data, $order, $settings) {
  // Bail out of this isn't a marketplace order.
  if ($order->type != 'commerce_marketplace_order') {
    return;
  }

  // Get a list of all of the individual store orders from the main marketplace order.
  $store_orders = EXAMPLE_marketplace_get_store_orders_from_marketplace_order($order);
  $currency_code = isset($data['currencyCode']) ? $data['currencyCode'] : 'USD';
  $percentage = 1 - floatval($settings['primary_receiver_rate']);

  foreach ($store_orders as $store_order) {
    // Get the email address for the store owning the order.
    $email = EXAMPLE_marketplace_get_email_for_store_order($store_order);

    // Set the order total and adjust for the primary receiver's allotted
    // amount. Set the percentage to the kept percentage - 1. This way if the
    // primary receiver wants to keep 5%, it will just set the amount to 95% of
    // each secondary receiver's amount.
    $order_total = field_get_items('commerce_order', $store_order, 'commerce_order_total');
    $order_total = commerce_paypal_price_amount(commerce_currency_convert($order_total[0]['amount'] * $percentage, $order_total[0]['currency_code'], $currency_code), $order_total[0]['currency_code']);

    // Add this receiver to the list.
    $data['receiverList']['receiver'][] = array(
      'email' => $email,
      'amount' => $order_total,
    );
  }

  // If there are more than 2 secondary receivers, then we must use the
  // EACHRECEIVER fees payment strategy.
  if (count($data['receiverList']['receiver']) > 2) {
    $data['feesPayer'] = 'EACHRECEIVER';
  }
}

Where, EXAMPLE_marketplace_get_email_for_store_order() returns the email address defined in #2 above.

Note that if you're using marketplace functionality (or if you're just handling multiple orders and therefore multiple individual transactions), there are some additional steps that you ought to do if you care about data consistency. Mainly, you'll want to look at implementing hook_commerce_paypal_adaptive_secondary_transaction() so that secondary transactions are created and/or updated appropriately. Here is an example:

function EXAMPLE_marketplace_commerce_paypal_adaptive_secondary_transaction($receiver_transaction, $order) {
  $email = $receiver_transaction['receiver'];
  $orders = EXAMPLE_marketplace_get_store_orders_from_marketplace_order($order);
  foreach ($orders as $id => $order) {
    if ($email == EXAMPLE_marketplace_get_email_for_store_order($order)) {
      $transactions = commerce_payment_transaction_load_multiple(array(), array('order_id' => $order->order_id));
      if (count($transactions) == 1) {
        return reset($transactions);
      }
      else {
        foreach ($transactions as $id => $transaction) {
          if ($transaction->remote_id == '') {
            return $transaction;
          }
        }
      }
    }
  }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.