Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function callPaymentRequest(PaymentRequestNeeds $needs)
 {
     try {
         $payload = ['gateway_id' => $this->getProviderConfig('gateway_id'), 'amount' => $needs->getAmount(), 'rand' => substr(md5(time() . microtime()), 0, 16), 'redirect_url' => urlencode($needs->getReturnUrl()), 'description' => $needs->get('description', '')];
         // create request and
         // get response
         $response = $this->getClient()->request('POST', static::PAYMENT_REQUEST_URL, ['form_params' => $payload])->getBody()->getContents();
         // check response is valid
         if (is_numeric($response) == false || $response < 0) {
             throw new PaymentGatewayResponseException($response);
         }
         // returns PaymentResponse with
         // `payment_url`, `payment_id` and `valid` fields
         return (new PaymentRequestResponse($this->generatePaymentUrl((int) $response)))->set('payment_id', (int) $response)->set('valid', $this->generateValid($payload['amount'], $payload['rand']));
     } catch (\Exception $e) {
         if ($e instanceof PaymentGatewayException) {
             throw $e;
         }
         throw new PaymentGatewayBadRequestException($e->getMessage(), $e->getCode(), $e);
     }
 }
 /**
  * @param PaymentRequestNeeds $needs
  * @return array
  * @throws InvalidPaymentNeedsException
  */
 protected function serializePaymentRequest(PaymentRequestNeeds $needs)
 {
     if ($needs->hasAll('amount', 'return_url', 'description') === false) {
         throw new InvalidPaymentNeedsException();
     }
     return ['MerchantID' => $this->getProviderConfig('api_key'), 'Amount' => $this->calculateAmount($needs->getAmount()), 'CallbackURL' => $needs->getReturnUrl(), 'Description' => $needs->get('description'), 'Email' => $needs->get('email'), 'Mobile' => $needs->get('mobile')];
 }