Skip to content

Commit

Permalink
PP-7001: Extend PHP SDK with possibility to send transaction confirma…
Browse files Browse the repository at this point in the history
…tion mail to recipient
  • Loading branch information
LLimani committed Sep 2, 2022
1 parent d4e2177 commit d9ddaf6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
30 changes: 30 additions & 0 deletions examples/TransactionReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

spl_autoload_register(function ($class) {
$root = dirname(__DIR__);
$classFile = $root . '/lib/' . str_replace('\\', '/', $class) . '.php';
if (file_exists($classFile)) {
require_once $classFile;
}
});

// $instanceName is a part of the url where you access your payrexx installation.
// https://{$instanceName}.payrexx.com
$instanceName = 'YOUR_INSTANCE_NAME';

// $secret is the payrexx secret for the communication between the applications
// if you think someone got your secret, just regenerate it in the payrexx administration
$secret = 'YOUR_SECRET';

$payrexx = new \Payrexx\Payrexx($instanceName, $secret);

$transaction = new \Payrexx\Models\Request\Transaction();
$transaction->setId(1);
$transaction->setRecipient('recipient@gmail.com');

try {
$response = $payrexx->receipt($transaction);
var_dump($response);
} catch (\Payrexx\PayrexxException $e) {
print $e->getMessage();
}
3 changes: 2 additions & 1 deletion lib/Payrexx/Communicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Communicator
'charge' => 'POST',
'refund' => 'POST',
'capture' => 'POST',
'receipt' => 'POST',
'cancel' => 'DELETE',
'delete' => 'DELETE',
'update' => 'PUT',
Expand Down Expand Up @@ -118,7 +119,7 @@ public function performApiRequest($method, \Payrexx\Models\Base $model)
$params['instance'] = $this->instance;

$id = isset($params['id']) ? $params['id'] : 0;
$act = in_array($method, ['refund', 'capture']) ? $method : '';
$act = in_array($method, ['refund', 'capture', 'receipt']) ? $method : '';
$apiUrl = sprintf(self::API_URL_FORMAT, $this->apiBaseDomain, 'v' . $this->version, $params['model'], $id, $act);

$httpMethod = $this->getHttpMethod($method) === 'PUT' && $params['model'] === 'Design'
Expand Down
18 changes: 18 additions & 0 deletions lib/Payrexx/Models/Request/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Transaction extends \Payrexx\Models\Base
protected $purpose;
/** @var string $referenceId */
protected $referenceId;
/** @var string $recipient */
protected $recipient;
protected $filterDatetimeUtcGreaterThan;
protected $filterDatetimeUtcLessThan;
protected $filterMyTransactionsOnly = false;
Expand Down Expand Up @@ -75,6 +77,22 @@ public function setReferenceId($referenceId)
$this->referenceId = $referenceId;
}

/**
* @return string
*/
public function getRecipient()
{
return $this->recipient;
}

/**
* @param string $recipient
*/
public function setRecipient($recipient)
{
$this->recipient = $recipient;
}

/**
* @return \DateTime
*/
Expand Down

0 comments on commit d9ddaf6

Please sign in to comment.