Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function processPaymentForm($data, $host, $invoice)
 {
     $rules = ['first_name' => 'required', 'last_name' => 'required', 'expiry_date_month' => ['required', 'regex:/^[0-9]*$/'], 'expiry_date_year' => ['required', 'regex:/^[0-9]*$/'], 'card_number' => ['required', 'regex:/^[0-9]*$/'], 'CVV' => ['required', 'regex:/^[0-9]*$/']];
     $validation = Validator::make($data, $rules);
     try {
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
     } catch (Exception $ex) {
         $invoice->logPaymentAttempt($ex->getMessage(), 0, [], [], null);
         throw $ex;
     }
     if (!($paymentMethod = $invoice->getPaymentMethod())) {
         throw new ApplicationException('Payment method not found');
     }
     /*
      * Send payment request
      */
     $gateway = Omnipay::create('Stripe');
     $gateway->initialize(array('apiKey' => $host->secret_key));
     $formData = ['firstName' => array_get($data, 'first_name'), 'lastName' => array_get($data, 'last_name'), 'number' => array_get($data, 'card_number'), 'expiryMonth' => array_get($data, 'expiry_date_month'), 'expiryYear' => array_get($data, 'expiry_date_year'), 'cvv' => array_get($data, 'CVV')];
     $totals = (object) $invoice->getTotalDetails();
     $response = $gateway->purchase(['amount' => $totals->total, 'currency' => $totals->currency, 'card' => $formData])->send();
     // Clean the credit card number
     $formData['number'] = '...' . substr($formData['number'], -4);
     if ($response->isSuccessful()) {
         $invoice->logPaymentAttempt('Successful payment', 1, $formData, null, null);
         $invoice->markAsPaymentProcessed();
         $invoice->updateInvoiceStatus($paymentMethod->invoice_status);
     } else {
         $errorMessage = $response->getMessage();
         $invoice->logPaymentAttempt($errorMessage, 0, $formData, null, null);
         throw new ApplicationException($errorMessage);
     }
 }
Exemplo n.º 2
0
 /**
  * @return \Omnipay\Common\GatewayInterface
  */
 public function getWorker()
 {
     if ($this->_worker === null) {
         $this->_worker = Omnipay::create($this->getGateway())->initialize($this->prepareData($this->data));
     }
     return $this->_worker;
 }
Exemplo n.º 3
0
 public function getSuccessPayment()
 {
     $gateway = Omnipay::create('PayPal_Express');
     $gateway->setUsername(ENV('PAYPAL_USERNAME'));
     $gateway->setPassword(ENV('PAYPAL_PASSWORD'));
     $gateway->setSignature(ENV('PAYPAL_SIGNATURE'));
     $gateway->setTestMode(ENV('PAYPAL_TEST'));
     $params = Session::get('params');
     $response = $gateway->completePurchase($params)->send();
     $paypalResponse = $response->getData();
     if (isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
         $user = Auth::user();
         // Assign Product to User
         $product = Product::find($params['product_id']);
         $user->products()->save($product, ['payment_type' => $params['payment_type'], 'amount' => $params['amount']]);
         foreach ($product->courses as $course) {
             $user->courses()->save($course);
         }
         // Assign Student Role to User
         if (!$user->hasRole('starter')) {
             $user->assignRole('starter');
         }
         $this->dispatch(new SendPurchaseConfirmationEmail($user, $product));
         return redirect()->route('thanks', $product->slug)->withSuccess('Your purchase of ' . $product->name . ' was successful.');
     } else {
         return redirect('purchase')->withErrors('Purchase failed.');
     }
 }
Exemplo n.º 4
0
 public function __construct($body = null)
 {
     parent::__construct($body);
     $this->platform = 'alipay_wap_express';
     $this->gatewayName = 'Alipay_WapExpress';
     $this->gateway = Omnipay::create($this->gatewayName);
 }
 /**
  * {@inheritDoc}
  */
 public function createConfig(array $config = array())
 {
     $config = ArrayObject::ensureArrayObject($config);
     $config->defaults($this->defaultConfig);
     $config->defaults($this->coreGatewayFactory->createConfig());
     $config->defaults(array('payum.action.capture' => new CaptureAction(), 'payum.action.convert_payment' => new ConvertPaymentAction(), 'payum.action.status' => new StatusAction()));
     if (false == $config['payum.api']) {
         $config['payum.required_options'] = array('type');
         $config->defaults(array('options' => array()));
         $config['payum.api.gateway'] = function (ArrayObject $config) {
             $config->validateNotEmpty($config['payum.required_options']);
             $gatewayFactory = Omnipay::getFactory();
             $gatewayFactory->find();
             $supportedTypes = $gatewayFactory->all();
             if (false == in_array($config['type'], $supportedTypes)) {
                 throw new LogicException(sprintf('Given type %s is not supported. Try one of supported types: %s.', $config['type'], implode(', ', $supportedTypes)));
             }
             $gateway = $gatewayFactory->create($config['type']);
             foreach ($config['options'] as $name => $value) {
                 $gateway->{'set' . strtoupper($name)}($value);
             }
             return $gateway;
         };
     }
     return (array) $config;
 }
Exemplo n.º 6
0
 public function __construct()
 {
     parent::__construct();
     $this->platform = 'alipay_express';
     $this->gatewayName = 'Alipay_MobileExpress';
     $this->gateway = Omnipay::create($this->gatewayName);
 }
Exemplo n.º 7
0
 /**
  * Configure the Stripe payment gateway
  *
  * @param array $config The gateway configuration
  * @return void
  */
 public function create(array $config)
 {
     // Create payment gateway
     $this->_name = 'Stripe';
     $this->_gateway = Omnipay::create('Stripe');
     $this->_gateway->setApiKey($config['apiKey']);
 }
    /**
     * {@inheritdoc}
     */
    public function addConfiguration(ArrayNodeDefinition $builder)
    {
        parent::addConfiguration($builder);

        $builder->children()
            ->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
            ->arrayNode('options')->isRequired()
                ->useAttributeAsKey('key')
                ->prototype('scalar')->end()
            ->end()
        ->end();

        $builder
            ->validate()
            ->ifTrue(function ($v) {
                $gatewayFactory = Omnipay::getFactory();
                $gatewayFactory->find();

                $supportedTypes = $gatewayFactory->all();
                if (false == in_array($v['type'], $supportedTypes) && !class_exists($v['type'])) {
                    throw new LogicException(sprintf(
                        'Given type %s is not supported. Try one of supported types: %s or use the gateway full class name.',
                        $v['type'],
                        implode(', ', $supportedTypes)
                    ));
                }

                return false;
            })
            ->thenInvalid('A message')
        ;
    }
 /**
  * Handle paying via this gateway
  *
  * @param Event $event
  *
  * @return mixed|void
  */
 public function onShoppingCartPay(Event $event)
 {
     if (!$this->isCurrentGateway($event['gateway'])) {
         return false;
     }
     $order = $this->getOrderFromEvent($event);
     $amount = $order->amount;
     $currency = $this->grav['config']->get('plugins.shoppingcart.general.currency');
     $description = $this->grav['config']->get('plugins.shoppingcart.payment.methods.stripe.description');
     $token = $order->extra['stripeToken'];
     $secretKey = $this->grav['config']->get('plugins.shoppingcart.payment.methods.stripe.secretKey');
     $gateway = Omnipay::create('Stripe');
     $gateway->setApiKey($secretKey);
     try {
         $response = $gateway->purchase(['amount' => $amount, 'currency' => $currency, 'description' => $description, 'token' => $token])->send();
         if ($response->isSuccessful()) {
             // mark order as complete
             $this->grav->fireEvent('onShoppingCartSaveOrder', new Event(['gateway' => $this->name, 'order' => $order]));
             $this->grav->fireEvent('onShoppingCartReturnOrderPageUrlForAjax', new Event(['gateway' => $this->name, 'order' => $order]));
         } elseif ($response->isRedirect()) {
             $response->redirect();
         } else {
             // display error to customer
             throw new \RuntimeException("Payment not successful: " . $response->getMessage());
         }
     } catch (\Exception $e) {
         // internal error, log exception and display a generic message to the customer
         throw new \RuntimeException('Sorry, there was an error processing your payment: ' . $e->getMessage());
     }
 }
Exemplo n.º 10
0
 public function __construct()
 {
     $this->platform = 'wechat';
     $this->gatewayName = 'WechatPay';
     $this->keys = ['body', 'detail', 'out_trade_no', 'total_fee', 'spbill_create_ip', 'notify_url'];
     $this->gateway = Omnipay::create($this->gatewayName);
 }
Exemplo n.º 11
0
 public function getSuccessPayment(Request $request)
 {
     $admin = User::where(['type' => 'admin'])->first();
     $gateway = Omnipay::create('PayPal_Express');
     $gateway->setUsername('fai1999.fa_api1.gmail.com');
     $gateway->setPassword('N8MALTPJ39RD3MG7');
     $gateway->setSignature('AVieiSDlpAV8gE.TnT6kpOEjJbTKAJJakY.PKQSfbkf.rc2Gy1N7vumm');
     $gateway->setTestMode(true);
     $params = Session::get('params');
     $response = $gateway->completePurchase($params)->send();
     $paypalResponse = $response->getData();
     // this is the raw response object
     if (isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
         // Response
         // print_r($paypalResponse);
     } else {
         //Failed transaction
     }
     $count = Transaction::where(['transactionid' => $paypalResponse['PAYMENTINFO_0_TRANSACTIONID']])->count();
     if ($count < 1) {
         Transaction::create(['senderid' => Auth::user()->id, 'transactionid' => $paypalResponse['PAYMENTINFO_0_TRANSACTIONID'], 'amount' => $paypalResponse['PAYMENTINFO_0_AMT'], 'recipientid' => $admin->id]);
         $balance = Balance::where(['userid' => Auth::user()->id])->first();
         $balance = $balance->balance + $paypalResponse['PAYMENTINFO_0_AMT'];
         Balance::where(['userid' => Auth::user()->id])->update(['balance' => $balance]);
     }
     if (Auth::user()->type != 'admin') {
         return redirect()->route('transactions');
     }
 }
Exemplo n.º 12
0
 public function __construct()
 {
     $this->platform = 'wechat';
     $this->gatewayName = 'WechatPay';
     $this->keys = ['send_name', 're_openid', 'total_amount', 'total_num', 'wishing', 'client_ip', 'act_name', 'remark'];
     $this->gateway = Omnipay::create($this->gatewayName);
 }
Exemplo n.º 13
0
 /**
  * Put Payment
  * @Rest\Post("/payment" )
  */
 public function postMakePaymentAction(Request $request)
 {
     $objEntityManager = $this->getDoctrine()->getManager();
     $objGateway = Omnipay::create('Stripe');
     $strJson = $request->getContent();
     $arrmixPaymentDetails = json_decode($strJson, true);
     $order = $objEntityManager->getRepository('BundlesOrderBundle:Orders')->find($arrmixPaymentDetails['order_id']);
     $objCustomer = $objEntityManager->getRepository('BundlesUserBundle:Customer')->find((int) $this->objSession->get('user/customer_id'));
     // Set secret key
     $objGateway->setApiKey('************');
     // Make Form data
     $formData = ['number' => $arrmixPaymentDetails['card_number'] . '', 'expiryMonth' => $arrmixPaymentDetails['expiry_month'] . '', 'expiryYear' => $arrmixPaymentDetails['expiry_year'] . '', 'cvv' => $arrmixPaymentDetails['cvv'] . ''];
     // Send purchase request
     $objResponse = $objGateway->purchase(['amount' => $order->getAmount() . '.00', 'currency' => 'USD', 'card' => $formData])->send();
     // Process response
     if ($objResponse->isSuccessful() || $objResponse->isRedirect()) {
         //         if( true ) {
         $objPayment = new Payment();
         $objPayment->setOrders($order);
         $objPayment->setCustomer($objCustomer);
         $objPayment->setTransactionId('transaction_' . (int) $this->objSession->get('user/customer_id'));
         $objPayment->setIsSuccess(true);
         $objPayment->setPaymentStatus('Completed');
         $objEntityManager->persist($objPayment);
         $objEntityManager->flush();
         return array('Payment' => array('id' => $objPayment->getId(), 'order_id' => $order->getId(), 'status' => 'success'));
     } else {
         return array('Payment' => array('status' => 'failed', 'order_id' => $order->getId()));
     }
 }
Exemplo n.º 14
0
 public function init()
 {
     $this->gateway = Omnipay::create('Alipay_Express');
     $this->gateway->setPartner($this->settings->get('pid'));
     $this->gateway->setKey($this->settings->get('key'));
     $this->gateway->setSellerEmail($this->settings->get('seller_email'));
     $this->logo = dirname(__FILE__) . '/logo.png';
 }
Exemplo n.º 15
0
 public function getOmniPayGateway()
 {
     $gateway = Omnipay::create($this->name);
     $gateway->setPartner($this->partner_id);
     $gateway->setKey($this->partner_key);
     $gateway->setSellerEmail($this->seller_email);
     return $gateway;
 }
Exemplo n.º 16
0
 public function testCallStatic()
 {
     $factory = m::mock('Omnipay\\Common\\GatewayFactory');
     $factory->shouldReceive('testMethod')->with('some-argument')->once()->andReturn('some-result');
     Omnipay::setFactory($factory);
     $result = Omnipay::testMethod('some-argument');
     $this->assertSame('some-result', $result);
 }
function createGateway($goId, $secureKey)
{
    $gateway = Omnipay::create('Gopay');
    $gateway->setTestMode(true);
    $gateway->setGoId($goId);
    $gateway->setSecureKey($secureKey);
    return $gateway;
}
Exemplo n.º 18
0
 /**
  * Assign middleware & initate the PayPal gateway
  */
 public function __construct()
 {
     $this->middleware('auth', ['except' => ['getPaymentWall']]);
     // Setup the PayPal gateway
     $this->gateway = Omnipay::create('PayPal_Rest');
     $this->gateway->initialize(['clientId' => settings('paypal_client_id'), 'secret' => settings('paypal_secret'), 'testMode' => false]);
     // Setup the PaymentWall instance
     Paymentwall_Config::getInstance()->set(['api_type' => Paymentwall_Config::API_VC, 'public_key' => settings('paymentwall_app_key'), 'private_key' => settings('paymentwall_key')]);
 }
Exemplo n.º 19
0
 /**
  * Verify if a payment has happened at Buckaroo
  *
  * @param $service
  * @param $amount
  * @param $transactionId
  * @return AbstractResponse
  */
 public function verify($service, $amount, $transactionId)
 {
     $gateway = Omnipay::create($service);
     $gateway->setWebsiteKey($this->credentials['websiteKey']);
     $gateway->setSecretKey($this->credentials['secretKey']);
     $gateway->setTestMode($this->testMode);
     $paymentData = ["amount" => $this->formatAmount($amount), "currency" => "EUR", "culture" => "nl-NL", "transactionId" => $transactionId];
     return $gateway->completePurchase($paymentData)->send();
 }
 public function setUp()
 {
     parent::setUp();
     $this->gateway = Omnipay::create('GlobalAlipay_App');
     $this->gateway->setPartner('123456');
     $this->gateway->setSellerId('*****@*****.**');
     $this->gateway->setPrivateKey(__DIR__ . '/Assets/private_key.pem');
     $this->gateway->setNotifyUrl('http://example.com/notify');
 }
 public function setUp()
 {
     parent::setUp();
     $this->gateway = Omnipay::create('GlobalAlipay_Wap');
     $this->gateway->setPartner('123456');
     $this->gateway->setKey('xxxxxxx');
     $this->gateway->setSignType('MD5');
     $this->gateway->setNotifyUrl('http://example.com/notify');
 }
Exemplo n.º 22
0
 /**
  * Configure the PayPalRest payment gateway
  *
  * @param array $config The gateway configuration
  * @return void
  */
 public function create(array $config)
 {
     // Create payment gateway
     $this->_name = 'PayPal_Rest';
     $this->_gateway = Omnipay::create($this->_name);
     $this->_gateway->setClientId($config['clientId']);
     $this->_gateway->setSecret($config['secret']);
     $this->_gateway->setTestMode($config['testMode']);
 }
Exemplo n.º 23
0
 public function setUp()
 {
     parent::setUp();
     $this->gateway = Omnipay::create('WechatPay');
     $this->gateway->setAppId('123456789');
     $this->gateway->setMchId('123456789');
     $this->gateway->setApiKey('XXSXXXSXXSXXSX');
     $this->gateway->setNotifyUrl('http://example.com/notify');
     $this->gateway->setTradeType('APP');
 }
Exemplo n.º 24
0
 public function purchase(array $parameters = array())
 {
     if (!empty($parameters['cardReference']) && $this->getPxPostPassword() && $this->getPxPostUsername()) {
         $gateway = Omnipay::create('PaymentExpress_PxPost');
         $gateway->setPassword($this->getPxPostPassword());
         $gateway->setUserName($this->getPxPostUsername());
         return $gateway->purchase($parameters);
     }
     return $this->createRequest('\\Omnipay\\PaymentExpress\\Message\\PxPayPurchaseRequest', $parameters);
 }
Exemplo n.º 25
0
 /**
  * Configure the PayPalExpress payment gateway
  *
  * @param array $config The gateway configuration
  * @return void
  */
 public function create(array $config)
 {
     // Create payment gateway
     $this->_name = 'PayPal_Express';
     $this->_gateway = Omnipay::create($this->_name);
     $this->_gateway->setUsername($config['username']);
     $this->_gateway->setPassword($config['password']);
     $this->_gateway->setSignature($config['signature']);
     $this->_gateway->setTestMode($config['testMode']);
 }
Exemplo n.º 26
0
 /**
  * @covers ::refund
  */
 public function testRefund()
 {
     $gateway = Omnipay::getFactory()->create('Dummy');
     $refund = $this->getMock('CL\\Purchases\\Refund', ['execute']);
     $params = ['test', 'test2'];
     $response = 'result response';
     $refund->expects($this->once())->method('execute')->with($this->identicalTo($gateway), $this->equalTo('refund'), $this->equalTo($params))->will($this->returnValue($response));
     $result = $refund->refund($gateway, $params);
     $this->assertEquals($response, $result);
 }
Exemplo n.º 27
0
 /**
  * @return \Omnipay\PayPal\ExpressGateway
  */
 protected function getOmnipayGateway()
 {
     $settings = $this->getSettings();
     $gateway = Omnipay::create('PayPal_Express');
     $gateway->setUsername($settings->getPayPalExpressUsername());
     $gateway->setPassword($settings->getPayPalExpressPassword());
     $gateway->setSignature($settings->getPayPalExpressSignature());
     $gateway->setTestMode(false);
     return $gateway;
 }
 public function setUp()
 {
     parent::setUp();
     $this->gateway = Omnipay::create('UnionPay_LegacyQuickPay');
     $this->gateway->setMerId('123456789');
     $this->gateway->setSecretKey('xxxxxxx');
     $this->gateway->setReturnUrl('http://example.com/return');
     $this->gateway->setNotifyUrl('http://example.com/notify');
     $this->gateway->setEnvironment('production');
 }
Exemplo n.º 29
0
 public function handlePayment(Request $request)
 {
     $amount = 0;
     $product = Product::find($request->product_id);
     $amount = $amount + $product->price;
     $amount = number_format($amount / 100, 2);
     switch ($request->provider) {
         case 'stripe':
             $gateway = Omnipay::create('Stripe');
             $token = $request->stripeToken;
             $params = ['amount' => $amount, 'currency' => 'USD', 'token' => $token, 'payment_type' => 'stripe', 'email' => Auth::user()->email, 'description' => $product->name];
             $gateway->setApiKey(ENV('STRIPE_SECRET'));
             break;
         case 'paypal':
             $gateway = Omnipay::create('PayPal_Express');
             $params = ['cancelUrl' => 'https://40daystartup.com/purchase', 'returnUrl' => ENV('PAYPAL_RETURN'), 'description' => $product->name, 'amount' => $amount, 'currency' => 'USD', 'product_id' => $product->id, 'payment_type' => 'paypal'];
             $gateway->setUsername(ENV('PAYPAL_USERNAME'));
             $gateway->setPassword(ENV('PAYPAL_PASSWORD'));
             $gateway->setSignature(ENV('PAYPAL_SIGNATURE'));
             $gateway->setTestMode(ENV('PAYPAL_TEST'));
             Session::put('params', $params);
             Session::save();
             break;
         default:
             # code...
             break;
     }
     //$response = $gateway->purchase($params)->send();
     $payment = $gateway->purchase($params);
     $data = $payment->getData();
     $data['receipt_email'] = Auth::user()->email;
     $data['metadata'] = ['email' => Auth::user()->email, 'user_id' => Auth::user()->id];
     $response = $payment->sendData($data);
     if ($response->isSuccessful()) {
         $user = Auth::user();
         // Assign Product to User
         $user->products()->save($product, ['payment_type' => $params['payment_type'], 'amount' => $params['amount']]);
         foreach ($product->courses as $course) {
             $user->courses()->save($course);
         }
         // Assign Student Role to User
         if (!$user->hasRole('starter')) {
             $user->assignRole('starter');
         }
         // Fire off purchase email
         $this->dispatch(new SendPurchaseConfirmationEmail($user, $product));
         Session::flush();
         return redirect()->route('thanks', $product->slug)->withSuccess('Your purchase of ' . $product->name . ' was successful.');
     } elseif ($response->isRedirect()) {
         $response->redirect();
     } else {
         return redirect('purchase')->withErrors([$response->getMessage()]);
     }
 }
Exemplo n.º 30
0
 /**
  * @param string $id
  * @param string $key
  * @return Gateway
  */
 public static function createInstance($id, $key)
 {
     $preparer = new Preparer();
     $signator = new Signator($key);
     $dataSignator = new DataSignator($preparer, $signator);
     /** @var \Omnipay\Tatrabank\Gateway $gateway */
     $gateway = Omnipay::create('Tatrabank');
     $gateway->setMerchantId($id);
     $gateway->setSignator($dataSignator);
     return $gateway;
 }