Add fees breakdown to capture

This commit is contained in:
Alex P 2022-02-14 10:46:33 +02:00
parent 2ab75368b4
commit a82b091bf1
3 changed files with 62 additions and 21 deletions

View file

@ -243,7 +243,10 @@ return array(
'api.factory.capture' => static function ( ContainerInterface $container ): CaptureFactory {
$amount_factory = $container->get( 'api.factory.amount' );
return new CaptureFactory( $amount_factory );
return new CaptureFactory(
$amount_factory,
$container->get( 'api.factory.seller-receivable-breakdown' )
);
},
'api.factory.purchase-unit' => static function ( ContainerInterface $container ): PurchaseUnitFactory {

View file

@ -51,6 +51,13 @@ class Capture {
*/
private $seller_protection;
/**
* The detailed breakdown of the capture activity (fees, ...).
*
* @var SellerReceivableBreakdown|null
*/
private $seller_receivable_breakdown;
/**
* The invoice id.
*
@ -68,13 +75,14 @@ class Capture {
/**
* Capture constructor.
*
* @param string $id The ID.
* @param CaptureStatus $status The status.
* @param Amount $amount The amount.
* @param bool $final_capture The final capture.
* @param string $seller_protection The seller protection.
* @param string $invoice_id The invoice id.
* @param string $custom_id The custom id.
* @param string $id The ID.
* @param CaptureStatus $status The status.
* @param Amount $amount The amount.
* @param bool $final_capture The final capture.
* @param string $seller_protection The seller protection.
* @param string $invoice_id The invoice id.
* @param string $custom_id The custom id.
* @param SellerReceivableBreakdown|null $seller_receivable_breakdown The detailed breakdown of the capture activity (fees, ...).
*/
public function __construct(
string $id,
@ -83,16 +91,18 @@ class Capture {
bool $final_capture,
string $seller_protection,
string $invoice_id,
string $custom_id
string $custom_id,
?SellerReceivableBreakdown $seller_receivable_breakdown
) {
$this->id = $id;
$this->status = $status;
$this->amount = $amount;
$this->final_capture = $final_capture;
$this->seller_protection = $seller_protection;
$this->invoice_id = $invoice_id;
$this->custom_id = $custom_id;
$this->id = $id;
$this->status = $status;
$this->amount = $amount;
$this->final_capture = $final_capture;
$this->seller_protection = $seller_protection;
$this->invoice_id = $invoice_id;
$this->custom_id = $custom_id;
$this->seller_receivable_breakdown = $seller_receivable_breakdown;
}
/**
@ -158,6 +168,15 @@ class Capture {
return $this->custom_id;
}
/**
* Returns the detailed breakdown of the capture activity (fees, ...).
*
* @return SellerReceivableBreakdown|null
*/
public function seller_receivable_breakdown() : ?SellerReceivableBreakdown {
return $this->seller_receivable_breakdown;
}
/**
* Returns the entity as array.
*
@ -177,6 +196,9 @@ class Capture {
if ( $details ) {
$data['status_details'] = array( 'reason' => $details->reason() );
}
if ( $this->seller_receivable_breakdown ) {
$data['seller_receivable_breakdown'] = $this->seller_receivable_breakdown->to_array();
}
return $data;
}
}

View file

@ -25,14 +25,26 @@ class CaptureFactory {
*/
private $amount_factory;
/**
* The SellerReceivableBreakdown factory.
*
* @var SellerReceivableBreakdownFactory
*/
private $seller_receivable_breakdown_factory;
/**
* CaptureFactory constructor.
*
* @param AmountFactory $amount_factory The amount factory.
* @param AmountFactory $amount_factory The amount factory.
* @param SellerReceivableBreakdownFactory $seller_receivable_breakdown_factory The SellerReceivableBreakdown factory.
*/
public function __construct( AmountFactory $amount_factory ) {
public function __construct(
AmountFactory $amount_factory,
SellerReceivableBreakdownFactory $seller_receivable_breakdown_factory
) {
$this->amount_factory = $amount_factory;
$this->amount_factory = $amount_factory;
$this->seller_receivable_breakdown_factory = $seller_receivable_breakdown_factory;
}
/**
@ -44,7 +56,10 @@ class CaptureFactory {
*/
public function from_paypal_response( \stdClass $data ) : Capture {
$reason = $data->status_details->reason ?? null;
$reason = $data->status_details->reason ?? null;
$seller_receivable_breakdown = isset( $data->seller_receivable_breakdown ) ?
$this->seller_receivable_breakdown_factory->from_paypal_response( $data->seller_receivable_breakdown )
: null;
return new Capture(
(string) $data->id,
@ -56,7 +71,8 @@ class CaptureFactory {
(bool) $data->final_capture,
(string) $data->seller_protection->status,
(string) $data->invoice_id,
(string) $data->custom_id
(string) $data->custom_id,
$seller_receivable_breakdown
);
}
}