Post-tax "discount"/apply deposit

I am trying to write a plugin in PHP for my client that allows the user to book a date through a third party system and pay the deposit, then generates an invoice for the balance.

Where I am getting suck is applying the deposit to the order. Since I can’t apply a payment that doesn’t total the amount due for the order, I thought I’d apply a OrderLineItemDiscount in the amount of the deposit, but that changes the tax basis, which is not what I want. So I tried CatalogDiscount where I can set the modifyTaxBasis to DO_NOT_MODIFY_TAX_BASIS, but then I get a missing “scope” error. But “scope” is not allowed in the catalogDiscount model.

I’m at a loss. Anyone have any ideas?

  • Using the PHP sdk

public function applyDeposit($response){
session_start();
msdlog($response);
// dotenv is used to read from the ‘.env’ file created for credentials
$dotenv = Dotenv\Dotenv::createImmutable(DIR);
$dotenv->load();
$orderResponse = unserialize($_SESSION[‘orderResponse’]);
$order_id = $orderResponse->order->id;
extract($_POST);

	$square_client = new SquareClient([
		'accessToken' => $_ENV['SQUARE_ACCESS_TOKEN'],
		'environment' => $_ENV['ENVIRONMENT'],
		'userAgentDetail' => 'bookAndPayParty',
	]);

	$order_api = $square_client->getOrdersApi();

	/*$line_item_discounts[] = Models\Builders\OrderLineItemDiscountBuilder::init()
		->name('Deposit')
		->type('FIXED_AMOUNT')
		->amountMoney(Models\Builders\MoneyBuilder::init()
			->amount($response->payment->amount_money->amount)
			->currency($response->payment->amount_money->currency)
			->build())
		->scope(Models\OrderLineItemDiscountScope::ORDER)
		->build();*/

	$line_item_discounts[] = Models\Builders\CatalogDiscountBuilder::init()
		->name('Deposit')
		->discountType('FIXED_AMOUNT')
		->amountMoney(Models\Builders\MoneyBuilder::init()
		                                          ->amount($response->payment->amount_money->amount)
		                                          ->currency($response->payment->amount_money->currency)
		                                          ->build())
		->scope('ORDER') <---error
		->modifyTaxBasis('DO_NOT_MODIFY_TAX_BASIS')
		->build();

	$update_order_request = Models\Builders\UpdateOrderRequestBuilder::init()
		->order(Models\Builders\OrderBuilder::init($this->getId())
			->id($order_id)
			->version($orderResponse->order->version)
			->discounts($line_item_discounts)
			->build()
		)
		->idempotencyKey($idempotencyKey)
		->build();

	try {
		$apiResponse = $order_api->updateOrder($order_id,$update_order_request);
		if ( $apiResponse->isSuccess() ) {
			$response = json_decode($apiResponse->getBody());
			msdlog($response);
			return json_encode($response);
		} else {
			$errors = $apiResponse->getErrors();
			msdlog('Error on applyDeposit');
			msdlog($errors);
			return false;
		}
	} catch (ApiException $e) {
		msdlog($e);
		return false;
	}
}

Is there a reason that your not using the Invoices API to take an initial payment as the deposit then schedule the rest for another date? :slightly_smiling_face:

Ah, because of this note:
" Invoice payments are managed by Square. You canno use Square APIs to pay invoices or associated orders directly. For more information, see Pay or Refund Invoices."

My client wants the user to make the initial payment on their website to secure the booking, and I need the payment info so that I can tell the booking software they use that the deposit is paid.

Did I perhaps understand this note incorrectly?

Ah, I see. Okay, in that case you will need to have a separate order and payment for the deposit and and one for remaining booking. You have a few options on how to tie the two together whether it be with a reference_id, metadata, or custom attributes. :slightly_smiling_face: