Include fraud response in order capture.

This commit is contained in:
Narek Zakarian 2022-04-25 19:16:09 +04:00
parent 4c1695788f
commit fd77690d46
2 changed files with 40 additions and 4 deletions

View file

@ -58,6 +58,13 @@ class Capture {
*/
private $seller_receivable_breakdown;
/**
* The fraud processor response (AVS, CVV ...).
*
* @var FraudProcessorResponse|null
*/
protected $fraud_processor_response;
/**
* The invoice id.
*
@ -83,6 +90,7 @@ class Capture {
* @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, ...).
* @param FraudProcessorResponse|null $fraud_processor_response The fraud processor response (AVS, CVV ...).
*/
public function __construct(
string $id,
@ -92,7 +100,8 @@ class Capture {
string $seller_protection,
string $invoice_id,
string $custom_id,
?SellerReceivableBreakdown $seller_receivable_breakdown
?SellerReceivableBreakdown $seller_receivable_breakdown,
?FraudProcessorResponse $fraud_processor_response
) {
$this->id = $id;
@ -103,6 +112,7 @@ class Capture {
$this->invoice_id = $invoice_id;
$this->custom_id = $custom_id;
$this->seller_receivable_breakdown = $seller_receivable_breakdown;
$this->fraud_processor_response = $fraud_processor_response;
}
/**
@ -177,6 +187,15 @@ class Capture {
return $this->seller_receivable_breakdown;
}
/**
* Returns the fraud processor response (AVS, CVV ...).
*
* @return FraudProcessorResponse|null
*/
public function fraud_processor_response() : ?FraudProcessorResponse {
return $this->fraud_processor_response;
}
/**
* Returns the entity as array.
*
@ -199,6 +218,9 @@ class Capture {
if ( $this->seller_receivable_breakdown ) {
$data['seller_receivable_breakdown'] = $this->seller_receivable_breakdown->to_array();
}
if ( $this->fraud_processor_response ) {
$data['fraud_processor_response'] = $this->fraud_processor_response->to_array();
}
return $data;
}
}

View file

@ -32,19 +32,29 @@ class CaptureFactory {
*/
private $seller_receivable_breakdown_factory;
/**
* The FraudProcessorResponseFactory factory.
*
* @var FraudProcessorResponseFactory
*/
protected $fraud_processor_response_factory;
/**
* CaptureFactory constructor.
*
* @param AmountFactory $amount_factory The amount factory.
* @param SellerReceivableBreakdownFactory $seller_receivable_breakdown_factory The SellerReceivableBreakdown factory.
* @param FraudProcessorResponseFactory $fraud_processor_response_factory The FraudProcessorResponseFactory factory.
*/
public function __construct(
AmountFactory $amount_factory,
SellerReceivableBreakdownFactory $seller_receivable_breakdown_factory
SellerReceivableBreakdownFactory $seller_receivable_breakdown_factory,
FraudProcessorResponseFactory $fraud_processor_response_factory
) {
$this->amount_factory = $amount_factory;
$this->seller_receivable_breakdown_factory = $seller_receivable_breakdown_factory;
$this->fraud_processor_response_factory = $fraud_processor_response_factory;
}
/**
@ -55,12 +65,15 @@ class CaptureFactory {
* @return Capture
*/
public function from_paypal_response( \stdClass $data ) : Capture {
$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;
$fraud_processor_response = isset( $data->processor_response ) ?
$this->fraud_processor_response_factory->from_paypal_response( $data->processor_response )
: null;
return new Capture(
(string) $data->id,
new CaptureStatus(
@ -72,7 +85,8 @@ class CaptureFactory {
(string) $data->seller_protection->status,
(string) $data->invoice_id,
(string) $data->custom_id,
$seller_receivable_breakdown
$seller_receivable_breakdown,
$fraud_processor_response
);
}
}