|
| 1 | +<?php |
| 2 | +require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php')); |
| 3 | + |
| 4 | +// …everything else can be loaded using TpUtils::requirePaths. |
| 5 | +TpUtils::requirePaths(array( |
| 6 | + array('TpPaymentReturnResponse.php'), |
| 7 | + array('exceptions', 'TpException.php') |
| 8 | +)); |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Michal Kandr |
| 12 | + */ |
| 13 | +class TpPaymentReturnHelper { |
| 14 | + protected static function getSignature($data) { |
| 15 | + return md5(http_build_query(array_filter($data))); |
| 16 | + } |
| 17 | + |
| 18 | + public static function returnPayment(TpMerchantConfig $config, $paymentId, $reason = null){ |
| 19 | + $client = new SoapClient($config->webServicesWsdl, ['cache_wsdl' => WSDL_CACHE_NONE]); |
| 20 | + $signature = static::getSignature(array( |
| 21 | + 'merchantId' => $config->merchantId, |
| 22 | + 'accountId' => $config->accountId, |
| 23 | + 'paymentId' => $paymentId, |
| 24 | + 'reason' => $reason, |
| 25 | + 'password' => $config->password |
| 26 | + )); |
| 27 | + $result = $client->returnPaymentRequest(array( |
| 28 | + 'merchantId' => $config->merchantId, |
| 29 | + 'accountId' => $config->accountId, |
| 30 | + 'paymentId' => $paymentId, |
| 31 | + 'reason' => $reason, |
| 32 | + 'signature' => $signature |
| 33 | + )); |
| 34 | + if( ! $result){ |
| 35 | + throw new TpException(); |
| 36 | + } |
| 37 | + return new TpPaymentReturnResponse($result); |
| 38 | + } |
| 39 | +} |
0 commit comments