Skip to content

Instantly share code, notes, and snippets.

@jsvini
Last active December 4, 2023 13:53
Show Gist options
  • Save jsvini/eefb0e58591a54d0948144f2c309cb90 to your computer and use it in GitHub Desktop.
Save jsvini/eefb0e58591a54d0948144f2c309cb90 to your computer and use it in GitHub Desktop.
<?php
// Arquivo:
// /wp-content/plugins/pagarme-payments-for-woocommerce/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/AbstractPayment.php
// Add o código abaixo na linha 55
// START SPLIT LOGIC
$FEE_PERCENTAGE = defined('PAGARME_SPLIT_FEE') ? PAGARME_SPLIT_FEE : 0;
$FEE_RECIPIENT_ID = defined('PAGARME_FEE_RECIPIENT_ID') ? PAGARME_FEE_RECIPIENT_ID : null;
$STORE_RECIPIENT_ID = defined('PAGARME_STORE_RECIPIENT_ID') ? PAGARME_STORE_RECIPIENT_ID : null;
if ($FEE_PERCENTAGE && $FEE_RECIPIENT_ID && $STORE_RECIPIENT_ID){
$newPayment->split = [
new \PagarmeCoreApiLib\Models\CreateSplitRequest(),
new \PagarmeCoreApiLib\Models\CreateSplitRequest(),
];
$fee = (int) bcmul($this->getAmount(), (string)( $FEE_PERCENTAGE / 100), 0);
$remainder = (int) bcsub($this->getAmount(), $fee, 0);
// FEE ACCOUNT
$newPayment->split[0]->recipientId = $FEE_RECIPIENT_ID;
$newPayment->split[0]->amount = $fee;
$newPayment->split[0]->type = "flat";
$newPayment->split[0]->options = new \PagarmeCoreApiLib\Models\CreateSplitOptionsRequest();
$newPayment->split[0]->options->chargeProcessingFee = false;
$newPayment->split[0]->options->chargeRemainderFee = true;
// STORE ACCOUNT
$newPayment->split[1]->recipientId = $STORE_RECIPIENT_ID;
$newPayment->split[1]->amount = $remainder;
$newPayment->split[1]->type = "flat";
$newPayment->split[1]->options = new \PagarmeCoreApiLib\Models\CreateSplitOptionsRequest();
$newPayment->split[1]->options->chargeProcessingFee = true; // store pay the processing fee
$newPayment->split[1]->options->chargeRemainderFee = false;
$newPayment->split[1]->options->liable = true; // store pay the chargeback fee
}
// END SPLIT LOGIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment