Skip to content

Commit

Permalink
Implement more API endpoints for Disputes API.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 10, 2023
1 parent be5b43d commit e8e1a79
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 10 deletions.
142 changes: 137 additions & 5 deletions src/Traits/PayPalAPI/DisputesActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,88 @@ public function provideDisputeEvidence(string $dispute_id, array $files)
return $this->doPayPalRequest();
}

/**
* Make offer to resolve dispute claim.
*
* @param string $dispute_id
* @param string $dispute_note
* @param float $amount
* @param string $refund_type
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_make-offer
*/
public function makeOfferToResolveDispute(string $dispute_id, string $dispute_note, float $amount, string $refund_type)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/make-offer";

$data['note'] = $dispute_note;
$data['offer_type'] = $refund_type;
$data['offer_amount'] = [
'currency_code' => $this->getCurrency(),
'value' => $amount,
];

$this->options['json'] = $data;

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Escalate dispute to claim.
*
* @param string $dispute_id
* @param string $dispute_note
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_escalate
*/
public function escalateDisputeToClaim(string $dispute_id, string $dispute_note)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/escalate";

$data['note'] = $dispute_note;

$this->options['json'] = $data;

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Accept offer to resolve dispute.
*
* @param string $dispute_id
* @param string $dispute_note
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer
*/
public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer";

$this->options['json'] = [
'note' => $dispute_note,
];

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Accept customer dispute claim.
*
Expand All @@ -81,7 +163,7 @@ public function provideDisputeEvidence(string $dispute_id, array $files)
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_accept-claim
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim
*/
public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = [])
{
Expand All @@ -98,7 +180,57 @@ public function acceptDisputeClaim(string $dispute_id, string $dispute_note, arr
}

/**
* Accept offer to resolve dispute.
* Update dispute status.
*
* @param string $dispute_id
* @param bool $merchant
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_require-evidence
*/
public function updateDisputeStatus(string $dispute_id, bool $merchant = true)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/require-evidence";

$data['action'] = ($merchant === true) ? 'SELLER_EVIDENCE' : 'BUYER_EVIDENCE';

$this->options['json'] = $data;

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Settle dispute.
*
* @param string $dispute_id
* @param bool $merchant
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_adjudicate
*/
public function settleDispute(string $dispute_id, bool $merchant = true)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/adjudicate";

$data['adjudication_outcome'] = ($merchant === true) ? 'SELLER_FAVOR' : 'BUYER_FAVOR';

$this->options['json'] = $data;

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Decline offer to resolve dispute.
*
* @param string $dispute_id
* @param string $dispute_note
Expand All @@ -107,11 +239,11 @@ public function acceptDisputeClaim(string $dispute_id, string $dispute_note, arr
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_accept-offer
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer
*/
public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note)
public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer";
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/deny-offer";

$this->options['json'] = [
'note' => $dispute_note,
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/PayPalAPI/Subscriptions/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function addShippingAddress(string $full_name, string $address_line_1, st
/**
* Add taxes when creating a subscription.
*
* @param float $price
* @param float $percentage
*
* @return \Srmklive\PayPal\Services\PayPal
*/
Expand Down
125 changes: 121 additions & 4 deletions tests/Feature/AdapterFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,30 @@ public function it_can_get_details_for_a_product()
$this->assertArrayHasKey('id', $response);
}

/** @test */
public function it_can_acknowledge_item_is_returned_for_raised_dispute()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockAcceptDisputesClaimResponse()
)
);

$response = $this->client->acknowledgeItemReturned(
'PP-D-4012',
'I have received the item back.',
'ITEM_RECEIVED'
);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('links', $response);
}

/** @test */
public function it_can_list_disputes()
{
Expand Down Expand Up @@ -441,6 +465,54 @@ public function it_throws_exception_if_file_size_as_evidence_exceeds_overall_lim
);
}

/** @test */
public function it_can_offer_to_resolve_dispute_claim()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockAcceptDisputesClaimResponse()
)
);

$response = $this->client->makeOfferToResolveDispute(
'PP-D-27803',
'Offer refund with replacement item.',
5.99,
'REFUND_WITH_REPLACEMENT'
);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('links', $response);
}

/** @test */
public function it_can_escalate_dispute_claim()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockAcceptDisputesClaimResponse()
)
);

$response = $this->client->escalateDisputeToClaim(
'PP-D-27803',
'Escalating to PayPal claim for resolution.'
);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('links', $response);
}

/** @test */
public function it_can_accept_dispute_claim()
{
Expand Down Expand Up @@ -488,7 +560,7 @@ public function it_can_accept_dispute_offer_resolution()
}

/** @test */
public function it_can_acknowledge_item_is_returned_for_raised_dispute()
public function it_can_update_dispute_status()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
Expand All @@ -501,10 +573,55 @@ public function it_can_acknowledge_item_is_returned_for_raised_dispute()
)
);

$response = $this->client->acknowledgeItemReturned(
$response = $this->client->updateDisputeStatus(
'PP-D-4012',
'I have received the item back.',
'ITEM_RECEIVED'
true
);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('links', $response);
}

/** @test */
public function it_can_settle_dispute()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockAcceptDisputesClaimResponse()
)
);

$response = $this->client->settleDispute(
'PP-D-4012',
true
);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('links', $response);
}

/** @test */
public function it_can_decline_dispute_offer_resolution()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockAcceptDisputesClaimResponse()
)
);

$response = $this->client->declineDisputeOfferResolution(
'PP-D-4012',
'I am not ok with the refund offered.'
);

$this->assertNotEmpty($response);
Expand Down

0 comments on commit e8e1a79

Please sign in to comment.