/**
  * @expectedException  \Laratalks\PaymentGateways\Exceptions\PaymentGatewayBadRequestException
  */
 public function testCallAndGetReturnUrlExceptedException()
 {
     $needs = new PaymentRequestNeeds(1000, 'http://localhost/');
     $needs->set('description', 'something');
     $paymentResponse = $this->provider->callPaymentRequest($needs);
     $this->assertTrue($paymentResponse instanceof PaymentRequestResponse);
 }
 /**
  * @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')];
 }
Пример #3
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);
     }
 }
Пример #4
0
// Call with provider name
// by this, you can change provider on-the-fly
$manager->provider('example')->callPaymentRequest($requestNeeds);
// OR set provider as default provider
// this set example as default provider
// and you can call provider methods directly from manager
$manager->setDefaultProvider('example');
$response = $manager->callPaymentRequest($requestNeeds);
$verifyNeeds = new PaymentNeeds();
$verifyNeeds->set('amount', 1000);
$verifyNeeds->set('payment_id', 15415648);
$response = $manager->callPaymentVerify($verifyNeeds);
// Zarinpal example
$provider = $manager->provider('zarinpal');
// create payment request:
$requestNeeds = new PaymentRequestNeeds();
$requestNeeds->setAmount(1000)->setReturnUrl('http://some_url')->set('description', 'some description')->set('mobile', 'YOUR_PHONE_NUMBER')->set('email', 'YOUR_EMAIL_ADDRESS');
// optional
$response = $manager->provider('zarinpal')->callPaymentRequest($requestNeeds);
$redirectUrl = $response->getPaymentUrl();
// each  request responses has  this method
// save the Authority to database
// we need that for payment verify
$authority = $response->get('authority');
// zarinpal provider response has this filed too.
// Redirect user to payment page
header('Location: ' . $response->getPaymentUrl());
// save response $data any where, you need these for payment verify
/**
 * @var $provider \Laratalks\PaymentGateways\Providers\Soap\ZarinpalProvider
 */