Integrate iDeal with Stripe Connect To Split Payments

310 views Asked by At

I'm running a marketplace website using Dokan Pro where I have integrated Stripe Connect. Now I want to integrate iDeal with it but they don't have it officially so I'm following Stripe's documentation to do some custom coding but I'm not able to achieve anything so far.

Stripe provided me this documentation:

https://stripe.com/docs/connect/direct-charges#create-a-charge

There's an official plugin on Stripe For Woocommerce that also has iDeal option but the problem is that it doesn't split payment because it doesn't work with Stripe Connect. I did try to edit it's code but it gives me an error when I send the application_fee parameter. Here's the code:

public function create_source( $order ) {
    $currency              = $order->get_currency();
    $return_url            = $this->get_stripe_return_url( $order );
    $post_data             = array();
    $post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
    $post_data['currency'] = strtolower( $currency );
    $post_data['type']     = 'ideal';
    $post_data['application_fee_amount']     = '10';
    $post_data['owner']    = $this->get_owner_details( $order );
    $post_data['redirect'] = array( 'return_url' => $return_url );

    if ( ! empty( $this->statement_descriptor ) ) {
        $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
    }

    WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' );

    return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' );
}

Any help would be appreciated.

1

There are 1 answers

2
Nolan H On

Assumption: I'm assuming for "split payments" you mean to handle when a customer does a single order/payment to your platform which includes goods/services from more than one provider. You need to allocate the payment and send some of it to more than one destination account.

A couple of items that I think are making things difficult for you:

  • Rather than Sources, I'd recommend looking at the updated Payment Intents guide for iDEAL. You should find this aligns much better with all the most recent documentation across Stripe's API.
  • If you're intending to split payments to multiple recipients, you will not be able to do so with direct charges. Instead, you should use "Separate Charges & Transfers" to allow you to send portions of the payment to more than one provider of goods/services.

On server:

// Create a PaymentIntent:
$paymentIntent = \Stripe\PaymentIntent::create([
  'amount' => 10000,
  'currency' => 'eur',
  'payment_method_types' => ['ideal'],
  'transfer_group' => 'YOUR_ORDER_ID_123',
]);

// Send $paymentIntent->client_secret to the client

On client:

//HTML
<div id="ideal-bank-element">
  <!-- A Stripe Element will be inserted here. -->
</div>

//JS
// Create an instance of the idealBank Element
var idealBank = elements.create('idealBank', options);

// Add an instance of the idealBank Element into
// the `ideal-bank-element` <div>
idealBank.mount('#ideal-bank-element');
...
    stripe.confirmIdealPayment(
    '{{PAYMENT_INTENT_CLIENT_SECRET}}',
    {
      payment_method: {
        ideal: idealBank,
        billing_details: {
          name: accountholderName.value,
        },
      },
      return_url: 'https://your-website.com/checkout/complete',
    }
  );

On server, later:

// Create a Transfer to a connected account (later):
$transfer = \Stripe\Transfer::create([
  'amount' => 7000,
  'currency' => 'eur',
  'destination' => 'acct_123',
  'transfer_group' => 'YOUR_ORDER_ID_123',
]);

// Create a second Transfer to another connected account (later):
$transfer = \Stripe\Transfer::create([
  'amount' => 2000,
  'currency' => 'eur',
  'destination' => 'acct_456',
  'transfer_group' => 'YOUR_ORDER_ID_123',
]);