-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved charges to Charge producer & fixed exception with empty charge_id.
- Loading branch information
1 parent
e4935d2
commit fe7828d
Showing
3 changed files
with
60 additions
and
26 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
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,50 @@ | ||
<?php | ||
|
||
namespace Mintance\Producers; | ||
|
||
use Mintance\Exceptions\Exception; | ||
|
||
/** | ||
* Class Charge | ||
* @package Mintance\Producers | ||
*/ | ||
class Charge extends Event { | ||
|
||
/** | ||
* Tracking Purchase event. | ||
* | ||
* @param float $amount Amount of money. | ||
* @param array $params Purchase params | ||
* Default params are: currency, products | ||
* | ||
* @return string Charge ID if success. | ||
* | ||
* @throws \Mintance\Exceptions\Exception Throws exception if something goes wrong. | ||
*/ | ||
public function track($amount, array $params = []) { | ||
|
||
$response = $this->_push($this->_buildEvent('New Charge', 'charge', array_merge($params, [ | ||
'value' => $amount | ||
]))); | ||
|
||
if(!empty($response['charge_id'])) { | ||
return $response['charge_id']; | ||
} else { | ||
throw new Exception('Charge sending error.'); | ||
} | ||
} | ||
|
||
/** | ||
* Function send's event to mintance. | ||
* | ||
* @param array $event Event data. | ||
* | ||
* @return \Mintance\Transport\AbstractTransport | ||
*/ | ||
protected function _push(array $event) { | ||
|
||
$this->_transport->setEndpoint('charges'); | ||
|
||
return $this->_transport->execute($event); | ||
} | ||
} |
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