-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
568 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Srmklive\PayPal\Tests\Adapter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Srmklive\PayPal\Tests\MockClientClasses; | ||
|
||
class DisputeActionsTest extends TestCase | ||
{ | ||
use MockClientClasses; | ||
|
||
/** @test */ | ||
public function it_can_accept_dispute_claim() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedMethod = 'acceptDisputeClaim'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-D-27803', 'Full refund to the customer.')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_accept_dispute_offer_resolution() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedMethod = 'acceptDisputeOfferResolution'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-000-000-651-454', 'I am ok with the refund offered.')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_acknowledge_item_is_returned_for_raised_dispute() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedMethod = 'acknowledgeItemReturned'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-000-000-651-454', 'I have received the item back.', 'ITEM_RECEIVED')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
<?php | ||
|
||
namespace Srmklive\PayPal\Tests\Adapter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Srmklive\PayPal\Tests\MockClientClasses; | ||
|
||
class DisputesTest extends TestCase | ||
{ | ||
use MockClientClasses; | ||
|
||
/** @test */ | ||
public function it_can_list_disputes() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"items": [ | ||
{ | ||
"dispute_id": "PP-000-003-648-191", | ||
"create_time": "2017-01-24T10:41:35.000Z", | ||
"update_time": "2017-01-24T11:40:32.000Z", | ||
"status": "WAITING_FOR_SELLER_RESPONSE", | ||
"reason": "MERCHANDISE_OR_SERVICE_NOT_RECEIVED", | ||
"dispute_state": "REQUIRED_OTHER_PARTY_ACTION", | ||
"dispute_amount": { | ||
"currency_code": "USD", | ||
"value": "50.00" | ||
}, | ||
"links": [ | ||
{ | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-003-648-191", | ||
"rel": "self", | ||
"method": "GET" | ||
} | ||
] | ||
}, | ||
{ | ||
"dispute_id": "PP-000-003-648-175", | ||
"create_time": "2017-01-24T10:37:23.000Z", | ||
"update_time": "2017-01-24T11:32:32.000Z", | ||
"status": "UNDER_REVIEW", | ||
"reason": "UNAUTHORISED", | ||
"dispute_amount": { | ||
"currency_code": "USD", | ||
"value": "20.00" | ||
}, | ||
"links": [ | ||
{ | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-003-648-175", | ||
"rel": "self", | ||
"method": "GET" | ||
} | ||
] | ||
} | ||
], | ||
"links": [ | ||
{ | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes", | ||
"rel": "self", | ||
"method": "GET" | ||
}, | ||
{ | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes", | ||
"rel": "first", | ||
"method": "GET" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedMethod = 'listDisputes'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_partially_update_a_dispute() | ||
{ | ||
$expectedResponse = ''; | ||
|
||
$expectedParams = \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); | ||
|
||
$expectedMethod = 'updateDispute'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'PP-D-27803')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_get_details_for_a_dispute() | ||
{ | ||
$expectedResponse = \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); | ||
|
||
$expectedMethod = 'showDisputeDetails'; | ||
|
||
$mockClient = $this->mock_client($expectedResponse, $expectedMethod, $this->getCredentials(), true); | ||
|
||
$mockClient->getAccessToken(); | ||
|
||
$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-D-4012')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Srmklive\PayPal\Tests\Client; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Srmklive\PayPal\Tests\MockClientClasses; | ||
|
||
class DisputeActionsTest extends TestCase | ||
{ | ||
use MockClientClasses; | ||
|
||
/** @test */ | ||
public function it_can_accept_dispute_claim() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/accept-claim'; | ||
$expectedParams = [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Accept-Language' => 'en_US', | ||
'Authorization' => 'Bearer some-token', | ||
], | ||
'json' => \GuzzleHttp\json_decode('{ | ||
"note": "Full refund to the customer.", | ||
"accept_claim_type": "REFUND" | ||
}', true), | ||
]; | ||
|
||
$mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); | ||
|
||
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_accept_dispute_offer_resolution() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/accept-offer'; | ||
$expectedParams = [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Accept-Language' => 'en_US', | ||
'Authorization' => 'Bearer some-token', | ||
], | ||
'json' => \GuzzleHttp\json_decode('{ | ||
"note": "I am ok with the refund offered." | ||
}', true), | ||
]; | ||
|
||
$mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); | ||
|
||
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_acknowledge_item_is_returned_for_raised_dispute() | ||
{ | ||
$expectedResponse = \GuzzleHttp\json_decode('{ | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"method": "GET", | ||
"href": "https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454" | ||
} | ||
] | ||
}', true); | ||
|
||
$expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/acknowledge-return-item'; | ||
$expectedParams = [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Accept-Language' => 'en_US', | ||
'Authorization' => 'Bearer some-token', | ||
], | ||
'json' => \GuzzleHttp\json_decode('{ | ||
"note": "I have received the item back.", | ||
"acknowledgement_type": "ITEM_RECEIVED" | ||
}', true), | ||
]; | ||
|
||
$mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); | ||
|
||
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); | ||
} | ||
} |
Oops, something went wrong.