Пример #1
0
 /**
  * @inheritdoc
  */
 public function callVerifyRequest(PaymentNeeds $needs, Request $request = null)
 {
     $request = $request === null ? Request::createFromGlobals() : $request;
     if ($needs->has('valid') === false) {
         throw new InvalidPaymentNeedsException();
     }
     if ($request->get('valid') === $needs->get('valid')) {
         return new PaymentVerifyResponse($request->get('trans_id'));
     }
     throw new PaymentNotVerifiedException();
 }
Пример #2
0
// payment verification
if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
    // AUTHORITY comes from payment request, response and you save it before
    $verifyNeeds = new PaymentNeeds();
    $verifyNeeds->set('amount', 1000)->set('authority', 'YOUR_AUTHORITY');
    $response = $provider->callVerifyRequest($verifyNeeds);
    $transactionId = $response->getTransactionId();
    // each verify response has this  method
    $status = $response->get('status');
    // zarinpal provider has status field too.
}
/**
 * Work with PaymentNeeds
 * every Request|Verify need extended `PaymentNeeds` class
 */
$needs = new PaymentNeeds();
$needs->has('key');
//  false
$needs->set('key', 'value');
$needs->has('key');
//  true
$needs->hasAll('key', 'attr', 'foo');
// false
$needs->set('attr', 'val');
$needs->hasAll('key', 'attr', 'foo');
// false
$needs->set('foo', 'bar');
$needs->hasAll('key', 'attr', 'foo');
// true
$value = $needs->get('key');
// value
 /**
  * @param PaymentNeeds $needs
  * @return array
  * @throws InvalidPaymentNeedsException
  */
 protected function serializeVerifyPayload(PaymentNeeds $needs)
 {
     if ($needs->hasAll('amount', 'authority')) {
         throw new InvalidPaymentNeedsException();
     }
     return ['MerchantID' => $this->getProviderConfig('api_key'), 'Amount' => $this->calculateAmount($needs->get('amount')), 'Authority' => $needs->get('authority')];
 }