Creating a milestone based transaction with broker commission using Escrow API

  0 comments
Share

In order to create a milestone transaction it needs to specify multiple items with the type set to milestone. You can create brokered transactions with a broker commission.  This is done by adding one or more broker_fee items to the transaction. You can specify more than one broker fee item if you wish to charge a broker fees to both the buyer or seller. There must be a broker in the transaction if you include broker fee items.

Then it needs to create an item array where we will pass item description, worker and client email, transaction amount in milestone type and brokerage details in broker_fee type in below format.

<?php $items = array(); $items[] = array( 'description' => 'Website Header Development', 'schedule' => array( array( 'payer_customer' => 'client@drupalchamp.com', 'amount' => '500.0', //this is the milestone amount 'beneficiary_customer' => 'worker@drupalchamp.com', ), ), 'title' => 'Website Header Development', 'inspection_period' => '1296000', 'type' => 'milestone', 'quantity' => '1', ); $items[] = array( 'type' => 'broker_fee', 'schedule' => array( array( 'payer_customer' => 'client@drupalchamp.com', 'agreed' => 'true', 'amount' => 50, //this is broker fee which will be paid by client 'beneficiary_customer' => 'me', ), ), array( 'type' => 'broker_fee', 'schedule' => array( array( 'payer_customer' => 'worker@drupalchamp.com', //seller email 'amount' => '40', //this is broker amount which will be deduct from worker actual amount 'beneficiary_customer' => 'me', ), ), ), ); ?>

Now you need to pass above $items array in "items" field in below code. The whole code will be following

<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.escrow.com/2017-09-01/transaction', CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERPWD => 'broker@drupalchamp.com:233_57fgvc5vIpiqwp6B8Z234234sfsdftwxHlge2pEtOeE5gRPuyzwiW6W', //broker email:api key(api key must be generated from broker account) CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), CURLOPT_POSTFIELDS => json_encode( array( 'currency' => 'usd', 'items' => $items, 'description' => 'Website Header Development tasks', 'parties' => array( array( 'customer' => 'me', 'role' => 'broker', ), array( 'customer' => 'client@drupalchamp.com', //buyer email 'role' => 'buyer', ), array( 'customer' => 'worker@drupalchamp.com', //seller email 'role' => 'seller', ), ), ) ) )); $output = curl_exec($curl); echo $output; curl_close($curl); ?>

The response of the above create Escrow milestone API will be

Example Response:-- { "close_date": null, "creation_date": "2019-04-03T11:01:38.880000+00:00", "currency": "usd", "description": "Website Header Development tasks", "id": 1780385, //unique transaction ID generated by Escrow.com "items": [ { "description": "Website Header Development", "fees": [ { "amount": "17.88", "amount_without_taxes": "17.88", //Escrow service fee "payer_customer": "client@drupalchamp.com", "split": "1.0", "type": "escrow" } ], "id": 2302550, "inspection_period": 259200, "quantity": 1, "schedule": [ { "amount": "500.00", "beneficiary_customer": "worker@drupalchamp.com", "payer_customer": "client@drupalchamp.com", "status": { "disbursed_to_beneficiary": false, "secured": false } } ], "status": { "accepted": false, "accepted_returned": false, "canceled": false, "received": false, "received_returned": false, "rejected": false, "rejected_returned": false, "shipped": false, "shipped_returned": false }, "title": "Website Header Development", "type": "milestone" }, { "fees": [ ], "parent_item_id": 2302550, "quantity": 1, "schedule": [ { "amount": "50.00", "beneficiary_customer": "broker@drupalchamp.com", "payer_customer": "client@drupalchamp.com", "status": { "disbursed_to_beneficiary": false, "secured": false } } ], "title": "Broker Fee", "type": "broker_fee" }, { "fees": [ ], "parent_item_id": 2302550, "quantity": 1, "schedule": [ { "amount": "40.00", "beneficiary_customer": "broker@drupalchamp.com", "payer_customer": "worker@drupalchamp.com", "status": { "disbursed_to_beneficiary": false, "secured": false } } ], "title": "Broker Fee", "type": "broker_fee" } ], "parties": [ { "agreed": false, "customer": "client@drupalchamp.com", "id": 4618358, "initiator": false, "next_step": "https://www.escrow-sandbox.com/agree?tid=1780385&token=a64ad7c3-adfa-4252-8392-c7cbf0d04367", //client/buyer can be agree to the transaction by this link "role": "buyer" }, { "agreed": false, "customer": "worker@drupalchamp.com", "disbursement_method_selected": false, "id": 4618359, "initiator": false, "next_step": "https://www.escrow-sandbox.com/agree?tid=1780385&token=9d146cbc-cb17-4ed5-9164-145528bebcc8", //worker/seller can be agree to the transaction by this link "role": "seller" }, { "agreed": true, "customer": "broker@drupalchamp.com", "disbursement_method_selected": false, "id": 4618360, "initiator": true, "role": "broker" }, { "agreed": true, "customer": "broker@drupalchamp.com", "id": 4618361, "role": "partner" } ] }

You can login in Escrow.com and check your generated transaction details like as below screenshot.

Escrow Details

Add new comment