RequestMoney Class
The RequestMoney class processes the IPCRequestMoney method, which allows a merchant to** initiate a funds transfer request** from a customer’s myPOS wallet. It can also be used to reverse a previously executed request.
Useful for billing agreements, mandate-based transactions, and one-click payments.
Class Overview
- Namespace:
Mypos\IPC - Located at:
RequestMoney.php - Extends:
Mypos\IPC\Base - Purpose: Create or reverse a money request based on a customer mandate or wallet
Method Summary
| Method | Return Type | Description |
|---|---|---|
__construct(Config $cnf) | - | Initializes the class with IPC configuration. |
setOrderID(string $orderID) | RequestMoney | Sets a unique identifier for the money request. |
getOrderID() | string | Returns the order ID. |
setAmount(float $amount) | void | Amount to be requested from the customer. |
getAmount() | float | Returns the requested amount. |
setCurrency(string $currency) | RequestMoney | Sets the ISO 4217 currency code. |
getCurrency() | string | Returns the currency. |
setCustomerWalletNumber(string $walletNumber) | void | Specifies the customer's myPOS wallet. |
getCustomerWalletNumber() | string | Returns the wallet number. |
setMandateReference(string $mandateReference) | void | Sets the unique ID of a mandate agreement. |
getMandateReference() | string | Returns the mandate reference. |
setReason(string $reason) | void | Explains the purpose of the money request. |
getReason() | string | Returns the reason for the transaction. |
setReversalIndicator(bool $flag) | void | Indicates if this is a reversal of a prior request. |
getReversalIndicator() | bool | Returns the reversal flag. |
validate() | bool | Checks that all required fields are set correctly. |
process() | Response | Sends the API request and returns the result. |
Inherited from Base
- _
addPostParam() _processPost(), _processHtmlPost()getCnf(), setCnf()getOutputFormat(), setOutputFormat()isValidSignature()
Example Usage
<?php
namespace Mypos\IPC;
/**
* Process IPC method: IPCRequestMoney.
* Collect, validate and send API params
*/
class RequestMoney extends Base
{
private $currency = 'EUR', $amount, $orderID, $mandateReference, $customerWalletNumber, $reversalIndicator, $reason;
/**
* Return Refund object
*
* @param Config $cnf
*/
public function __construct(Config $cnf)
{
$this->setCnf($cnf);
}
/**
* Refund amount
*
* @param float $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}
/**
* Request identifier - must be unique
*
* @param string $orderID
*
* @return RequestMoney
*/
public function setOrderID($orderID)
{
$this->orderID = $orderID;
return $this;
}
/**
* Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
*
* @param string $mandateReference
*/
public function setMandateReference($mandateReference)
{
$this->mandateReference = $mandateReference;
}
/**
* Identifier of the client’s (debtor’s) myPOS account
*
* @param string $customerWalletNumber
*/
public function setCustomerWalletNumber($customerWalletNumber)
{
$this->customerWalletNumber = $customerWalletNumber;
}
/**
* Reversal of the previously executed Request money transaction.
*
* @param bool $reversalIndicator
*/
public function setReversalIndicator($reversalIndicator)
{
$this->reversalIndicator = $reversalIndicator;
}
/**
* The reason for the transfer.
*
* @param string $reason
*/
public function setReason($reason)
{
$this->reason = $reason;
}
/**
* Initiate API request
*
* @return Response
*/
public function process()
{
$this->validate();
$this->_addPostParam('IPCmethod', 'IPCRequestMoney');
$this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
$this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
$this->_addPostParam('SID', $this->getCnf()->getSid());
$this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
$this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
$this->_addPostParam('Source', $this->getCnf()->getSource());
$this->_addPostParam('Currency', $this->getCurrency());
$this->_addPostParam('Amount', $this->getAmount());
$this->_addPostParam('OrderID', $this->getOrderID());
$this->_addPostParam('MandateReference', $this->getMandateReference());
$this->_addPostParam('CustomerWalletNumber', $this->getCustomerWalletNumber());
$this->_addPostParam('ReversalIndicator', (int)$this->getReversalIndicator());
$this->_addPostParam('Reason', $this->getReason());
$this->_addPostParam('OutputFormat', $this->getOutputFormat());
return $this->_processPost();
}
/**
* Validate all set refund details
*
* @return boolean
* @throws IPC_Exception
*/
public function validate()
{
try {
$this->getCnf()->validate();
} catch (\Exception $ex) {
throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
}
if ($this->getAmount() == null || !Helper::isValidAmount($this->getAmount())) {
throw new IPC_Exception('Invalid Amount');
}
if ($this->getCurrency() == null || !Helper::isValidCurrency($this->getCurrency())) {
throw new IPC_Exception('Invalid Currency');
}
if ($this->getOrderID() == null || !Helper::isValidOrderId($this->getOrderID())) {
throw new IPC_Exception('Invalid OrderId');
}
if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
throw new IPC_Exception('Invalid Output format');
}
return true;
}
/**
* Refund amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* ISO-4217 Three letter currency code
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* ISO-4217 Three letter currency code
*
* @param string $currency
*
* @return RequestMoney
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* Request identifier - must be unique
*
* @return string
*/
public function getOrderID()
{
return $this->orderID;
}
/**
* Unique identifier of the agreement (mandate) between the merchant and the client (debtor). Up to 127 characters.
*
* @return string
*/
public function getMandateReference()
{
return $this->mandateReference;
}
/**
* Identifier of the client’s (debtor’s) myPOS account
*
* @return string
*/
public function getCustomerWalletNumber()
{
return $this->customerWalletNumber;
}
/**
* Reversal of the previously executed Request money transaction.
*
* @return bool
*/
public function getReversalIndicator()
{
return $this->reversalIndicator;
}
/**
* The reason for the transfer.
*
* @return string
*/
public function getReason()
{
return $this->reason;
}
}
Use Cases
Use the RequestMoney class when:
- You want to charge a customer via their myPOS wallet
- You have an active mandate agreement with the customer
- You want to automate recurring or one-off billing
- You need to reverse a previous money request due to an error or cancellation