Skip to content

Commit

Permalink
Merge pull request #31 from payrexx/PP-7658
Browse files Browse the repository at this point in the history
PP-7658: Add Endpoint for Creating a Transaction
  • Loading branch information
ukramer authored Sep 26, 2022
2 parents a198ef9 + 1c05b1e commit f511648
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/TransactionCreate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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();

// amount multiplied by 100
$transaction->setAmount(89.25 * 100);

// VAT rate percentage (nullable)
$transaction->setVatRate(7.70);

// currency ISO code
$transaction->setCurrency('CHF');

// optional: add contact information which should be stored along with payment
$transaction->addField($type = 'forename', $value = 'Max');
$transaction->addField($type = 'surname', $value = 'Mustermann');
$transaction->addField($type = 'email', $value = 'max.muster@payrexx.com');

try {
$response = $payrexx->create($transaction);
var_dump($response);
} catch (\Payrexx\PayrexxException $e) {
print $e->getMessage();
}
60 changes: 60 additions & 0 deletions lib/Payrexx/Models/Request/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ class Transaction extends \Payrexx\Models\Base
{
/** @var int $amount */
protected $amount;
/** @var string $currency */
protected $currency;
/** @var string $purpose */
protected $purpose;
/** @var float $vatRate */
protected $vatRate;
/** @var array $fields */
protected $fields;
/** @var string $referenceId */
protected $referenceId;
/** @var string $recipient */
Expand All @@ -45,6 +51,22 @@ public function setAmount($amount)
$this->amount = $amount;
}

/**
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}

/**
* @param string $currency
*/
public function setCurrency(string $currency): void
{
$this->currency = $currency;
}

/**
* @return string
*/
Expand All @@ -61,6 +83,44 @@ public function setPurpose($purpose)
$this->purpose = $purpose;
}

/**
* @return float|null
*/
public function getVatRate(): ?float
{
return $this->vatRate;
}

/**
* @param float $vatRate
*/
public function setVatRate(float $vatRate): void
{
$this->vatRate = $vatRate;
}

/**
* @return array
*/
public function getFields(): array
{
return $this->fields ?? [];
}

/**
* @param string $type
* @param string $value
* @param array $name
* @return void
*/
public function addField(string $type, string $value, array $name = []): void
{
$this->fields[$type] = [
'value' => $value,
'name' => $name,
];
}

/**
* @return string
*/
Expand Down

0 comments on commit f511648

Please sign in to comment.