Skip to content

Commit

Permalink
Refactor & add tests for Disputes API.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 9, 2020
1 parent d066667 commit 523c0dc
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Traits/PayPalAPI/Disputes.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function updateDispute(array $data, $dispute_id)

$this->verb = 'patch';

return $this->doPayPalRequest();
return $this->doPayPalRequest(false);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/PayPalHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ protected function setCurlConstants()
*
* @return void
*/
public function setClient($client=null)
public function setClient($client = null)
{
if ($client instanceof HttpClient) {
$this->client = $client;

return;
}

Expand Down
39 changes: 39 additions & 0 deletions tests/Feature/AdapterFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,45 @@ public function it_can_list_disputes()
$this->assertArrayHasKey('items', $response);
}

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

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

$expectedParams = $this->updateDisputeParams();

$response = $this->client->updateDispute($expectedParams, 'PP-D-27803');

$this->assertEmpty($response);
}

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

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

$response = $this->client->showDisputeDetails('PP-D-4012');

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

/** @test */
public function it_can_list_invoices()
{
Expand Down
22 changes: 22 additions & 0 deletions tests/RequestPayloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ protected function updateProductParams()
]', true);
}

/**
* @return array
*/
protected function updateDisputeParams()
{
return \GuzzleHttp\json_decode('[
{
"op": "add",
"path": "/partner_actions/-",
"value": {
"id": "AMX-22345",
"name": "ACCEPT_DISPUTE",
"create_time": "2018-01-12T10:41:35.000Z",
"status": "PENDING"
}
}
]', true);
}

/**
* @return array
*/
protected function invoiceSearchParams()
{
return \GuzzleHttp\json_decode('{
Expand Down
104 changes: 104 additions & 0 deletions tests/ResponsePayloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

trait ResponsePayloads
{
/**
* @return array
*/
private function mockAccessTokenResponse()
{
return [
Expand All @@ -16,6 +19,9 @@ private function mockAccessTokenResponse()
];
}

/**
* @return array
*/
private function mockCreateCatalogProductsResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -43,6 +49,9 @@ private function mockCreateCatalogProductsResponse()
}', true);
}

/**
* @return array
*/
private function mockListCatalogProductsResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -96,6 +105,9 @@ private function mockListCatalogProductsResponse()
}', true);
}

/**
* @return array
*/
private function mockGetCatalogProductsResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -123,6 +135,9 @@ private function mockGetCatalogProductsResponse()
}', true);
}

/**
* @return array
*/
private function mockListDisputesResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -180,6 +195,86 @@ private function mockListDisputesResponse()
}', true);
}

/**
* @return array
*/
private function mockGetDisputesResponse()
{
return \GuzzleHttp\json_decode('{
"dispute_id": "PP-D-4012",
"create_time": "2019-04-11T04:18:00.000Z",
"update_time": "2019-04-21T04:19:08.000Z",
"disputed_transactions": [
{
"seller_transaction_id": "3BC38643YC807283D",
"create_time": "2019-04-11T04:16:58.000Z",
"transaction_status": "REVERSED",
"gross_amount": {
"currency_code": "USD",
"value": "192.00"
},
"buyer": {
"name": "Lupe Justin"
},
"seller": {
"email": "[email protected]",
"merchant_id": "5U29WL78XSAEL",
"name": "Lesley Paul"
}
}
],
"reason": "MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED",
"status": "RESOLVED",
"dispute_amount": {
"currency_code": "USD",
"value": "96.00"
},
"dispute_outcome": {
"outcome_code": "RESOLVED_BUYER_FAVOUR",
"amount_refunded": {
"currency_code": "USD",
"value": "96.00"
}
},
"dispute_life_cycle_stage": "CHARGEBACK",
"dispute_channel": "INTERNAL",
"messages": [
{
"posted_by": "BUYER",
"time_posted": "2019-04-11T04:18:04.000Z",
"content": "SNAD case created through automation"
}
],
"extensions": {
"merchandize_dispute_properties": {
"issue_type": "SERVICE",
"service_details": {
"sub_reasons": [
"INCOMPLETE"
],
"purchase_url": "https://ebay.in"
}
}
},
"offer": {
"buyer_requested_amount": {
"currency_code": "USD",
"value": "96.00"
}
},
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-4012",
"rel": "self",
"method": "GET"
}
]
}', true);
}

/**
* @return array
*/
private function mockListInvoicesResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -306,6 +401,9 @@ private function mockListInvoicesResponse()
}', true);
}

/**
* @return array
*/
private function mockSearchInvoicesResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -366,6 +464,9 @@ private function mockSearchInvoicesResponse()
}', true);
}

/**
* @return array
*/
private function mockListTransactionsResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down Expand Up @@ -521,6 +622,9 @@ private function mockListTransactionsResponse()
}', true);
}

/**
* @return array
*/
private function mockListBalancesResponse()
{
return \GuzzleHttp\json_decode('{
Expand Down

0 comments on commit 523c0dc

Please sign in to comment.