-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from mercadopago/release/1.9.0
Release 1.9.0
- Loading branch information
Showing
6 changed files
with
260 additions
and
1 deletion.
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
138 changes: 138 additions & 0 deletions
138
src/MercadoPago/Entities/AdvancedPayments/AdvancedPayment.php
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,138 @@ | ||
<?php | ||
|
||
|
||
namespace MercadoPago\AdvancedPayments; | ||
|
||
use MercadoPago\Annotation\RestMethod; | ||
use MercadoPago\Annotation\RequestParam; | ||
use MercadoPago\Annotation\Attribute; | ||
use MercadoPago\Entity; | ||
|
||
/** | ||
* @RestMethod(resource="/v1/advanced_payments", method="create") | ||
* @RestMethod(resource="/v1/advanced_payments/:id", method="read") | ||
* @RestMethod(resource="/v1/advanced_payments/search", method="search") | ||
* @RestMethod(resource="/v1/advanced_payments/:id", method="update") | ||
* @RestMethod(resource="/v1/advanced_payments/:id/refunds", method="refund") | ||
* @RequestParam(param="access_token") | ||
*/ | ||
class AdvancedPayment extends Entity | ||
{ | ||
|
||
/** | ||
* @var | ||
* @Attribute() | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var | ||
* @Attribute() | ||
*/ | ||
protected $application_id; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $payments; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $disbursements; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $payer; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $external_reference; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $description; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $binary_mode; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $status; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $capture; | ||
|
||
/** | ||
* @return mixed | ||
* @throws \Exception | ||
*/ | ||
public function cancel() { | ||
$this->status = 'cancelled'; | ||
|
||
return $this->update(); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
* @throws \Exception | ||
*/ | ||
public function capture() | ||
{ | ||
$this->capture = true; | ||
|
||
return $this->update(); | ||
} | ||
|
||
/** | ||
* @param int $amount | ||
* @return bool | ||
* @throws \Exception | ||
*/ | ||
public function refund($amount = 0){ | ||
$refund = new Refund(["advanced_payment_id" => $this->id]); | ||
if ($amount > 0){ | ||
$refund->amount = $amount; | ||
} | ||
|
||
if ($refund->save()){ | ||
$advanced_payment = self::get($this->id); | ||
$this->_fillFromArray($this, $advanced_payment->toArray()); | ||
return true; | ||
}else{ | ||
$this->error = $refund->error; | ||
return false; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @param $disbursement_id | ||
* @param int $amount | ||
* @return bool | ||
* @throws \Exception | ||
*/ | ||
public function refundDisbursement($disbursement_id, $amount = 0){ | ||
$refund = new DisbursementRefund(["advanced_payment_id" => $this->id, "disbursement_id" => $disbursement_id]); | ||
if ($amount > 0){ | ||
$refund->amount = $amount; | ||
} | ||
|
||
if ($refund->save()){ | ||
$advanced_payment = self::get($this->id); | ||
$this->_fillFromArray($this, $advanced_payment->toArray()); | ||
return true; | ||
}else{ | ||
$this->error = $refund->error; | ||
return false; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/MercadoPago/Entities/AdvancedPayments/DisbursementRefund.php
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,54 @@ | ||
<?php | ||
|
||
namespace MercadoPago\AdvancedPayments; | ||
|
||
use MercadoPago\Annotation\RestMethod; | ||
use MercadoPago\Annotation\RequestParam; | ||
use MercadoPago\Annotation\Attribute; | ||
use MercadoPago\Entity; | ||
|
||
/** | ||
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/disbursements/:disbursement_id/refunds", method="create") | ||
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/disbursements/:disbursement_id/refunds/:refund_id", method="read") | ||
* @RequestParam(param="access_token") | ||
*/ | ||
class DisbursementRefund extends Entity { | ||
|
||
/** | ||
* @Attribute() | ||
*/ | ||
protected $id; | ||
/** | ||
* @Attribute(serialize=false) | ||
*/ | ||
protected $payment_id; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $amount; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $metadata; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $source; | ||
/** | ||
* @Attribute(readOnly=true) | ||
*/ | ||
protected $date_created; | ||
|
||
/** | ||
* @Attribute(serialize=false) | ||
*/ | ||
protected $advanced_payment_id; | ||
|
||
/** | ||
* @Attribute(serialize=false) | ||
*/ | ||
protected $disbursement_id; | ||
|
||
} | ||
|
||
?> |
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,44 @@ | ||
<?php | ||
|
||
namespace MercadoPago\AdvancedPayments; | ||
|
||
use MercadoPago\Annotation\RestMethod; | ||
use MercadoPago\Annotation\RequestParam; | ||
use MercadoPago\Annotation\Attribute; | ||
use MercadoPago\Entity; | ||
|
||
/** | ||
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/refunds", method="create") | ||
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/refunds/:refund_id", method="read") | ||
* @RequestParam(param="access_token") | ||
*/ | ||
class Refund extends Entity { | ||
|
||
/** | ||
* @Attribute() | ||
*/ | ||
protected $id; | ||
/** | ||
* @Attribute(serialize=false) | ||
*/ | ||
protected $payment_id; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $amount; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $metadata; | ||
/** | ||
* @Attribute() | ||
*/ | ||
protected $source; | ||
/** | ||
* @Attribute(readOnly=true) | ||
*/ | ||
protected $date_created; | ||
|
||
} | ||
|
||
?> |
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
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