<?php
namespace Srmklive\PayPal\Traits\PayPalAPI;
use GuzzleHttp\Psr7;
use Srmklive\PayPal\Services\VerifyDocuments;
trait DisputesActions
{
/**
* Acknowledge item has been returned.
*
* @param string $dispute_id
* @param string $dispute_note
* @param string $acknowledgement_type
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_acknowledge-return-item
*/
public function acknowledgeItemReturned(string $dispute_id, string $dispute_note, string $acknowledgement_type)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item";
$this->options['json'] = [
'note' => $dispute_note,
'acknowledgement_type' => $acknowledgement_type,
];
$this->verb = 'post';
return $this->doPayPalRequest();
}
/**
* Providence evidence in support of a dispute.
*
* @param string $dispute_id
* @param array $file_path
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence
*/
public function provideDisputeEvidence(string $dispute_id, array $files)
{
if (VerifyDocuments::isValidEvidenceFile($files) === false) {
$this->throwInvalidEvidenceFileException();
}
$this->apiEndPoint = "/v1/customer/disputes/{$dispute_id}/provide-evidence";
$this->setRequestHeader('Content-Type', 'multipart/form-data');
$this->options['multipart'] = [];
foreach ($files as $file) {
$this->options['multipart'][] = [
'name' => basename($file),
'contents' => Psr7\Utils::tryFopen($file, 'r'),
];
}
$this->verb = 'post';
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.
*
* @param string $dispute_id
* @param string $dispute_note
* @param array $data
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim
*/
public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = [])
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim";
$data['note'] = $dispute_note;
$data['accept_claim_type'] = 'REFUND';
$this->options['json'] = $data;
$this->verb = 'post';
return $this->doPayPalRequest();
}
/**
* 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
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer
*/
public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/deny-offer";
$this->options['json'] = [
'note' => $dispute_note,
];
$this->verb = 'post';
return $this->doPayPalRequest();
}
}
Get access token to initiates payment transaction.
generate-token
| Parameter | Type | Comments |
|---|---|---|
| client_id | string | Enter merchant API client/primary key |
| secret_id | string | Enter merchant API secret key |
| env | string | Enter merchant API environment |
| merchant_id | string | Enter merchant API merchant id |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url. 'v1/generate-token', [
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'client_id' => '$client_id',
'secret_id' => 'secret_id',
'env' => 'env',
'merchant_id' => 'merchant_id',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Successfully token is generated"
]
},
"data": {
"token":"eyJpdiI6InpkczhjTjhQdVhUL2lKQ0pSUUx6aUE9PSIsInZhbHVlIjoiVGVBTVBDTXltbjNZcEIvdEJveGpTSno3TU5NRUtnVkhCZ1pHTFNCUnZGQ2UxMnYxN202cEE1YVRDTEFsc0ZERExoTjdtL0dTL2xoU3QzeUJJOExiMUx5T0w1L0llUXhTUkU1cWVLWEdEbEplb0dKNXcwbTNRM0VxdkUwYzZuNFdtNkhMQ0pRZysyNWkvdzBxSlBoSVBSOGFTekNnR2RXNHVtcG9lMGZOTmNCcm1hR3c5Sk9KTnB4Y3ltZDl6cm90MThrR21Ca3B1azc3bXRiQ0J6SW96UVo1elNkU1ZqeE05bTcwWGp1MEUxWlJFdnNWTmpSbnVpeW92b2U4dXZkUGgyb1VmK0luaGdyaFlsVTZlcVpVRnZlTG1DeFF6Ykk2T2h6Z3JzbnIyNHpNdHowSE5JdDR0Y0pZT20zUm1XYW8iLCJtYWMiOiJlY2M4NGE1OGUzYzkzYzk0YzljNmVmNjE0YWI0ZDIwOGI3NDQ2YWEyY2ZhNzc0NzE4ZmY1ZmYyMz
IyZmQzNDY1IiwidGFnIjoiIn0=",
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid credentials."
]
},
"data": null,
"type": "error"
}