/**
     * {@inheritDoc}
     */
    public function execute($request)
    {
        /** @var $request CreateCharge */
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if (is_array($model['card'])) {
            throw new LogicException('The token has already been used.');
        }

        if (empty($model['card'])) {
            throw new LogicException('The token has to be set.');
        }

        try {
            \Stripe::setApiKey($this->keys->getSecretKey());

            $charge = \Stripe_Charge::create((array) $model);

            $model->replace($charge->__toArray(true));
        } catch (\Stripe_CardError $e) {
            $model->replace($e->getJsonBody());
        }
    }
    /**
     * {@inheritDoc}
     */
    public function execute($request)
    {
        /** @var $request ObtainToken */
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if ($model['card']) {
            throw new LogicException('The token has already been set.');
        }

        $getHttpRequest = new GetHttpRequest();
        $this->payment->execute($getHttpRequest);
        if ($getHttpRequest->method == 'POST' && isset($getHttpRequest->request['stripeToken'])) {
            $model['card'] = $getHttpRequest->request['stripeToken'];

            return;
        }

        $this->payment->execute($renderTemplate = new RenderTemplate($this->templateName, array(
            'model' => $model,
            'publishable_key' => $this->keys->getPublishableKey(),
        )));

        throw new HttpResponse($renderTemplate->getResult());
    }
示例#3
0
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request CreateToken */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     try {
         Stripe::setApiKey($this->keys->getSecretKey());
         $token = Token::create($model->toUnsafeArrayWithoutLocal());
         $model->replace($token->__toArray(true));
     } catch (Error\Base $e) {
         $model->replace($e->getJsonBody());
     }
 }
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request CreateCharge */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $model->validateNotEmpty(array('plan'));
     if (false == $model['card']) {
         $this->gateway->execute(new ObtainToken($model));
     }
     try {
         Stripe::setApiKey($this->keys->getSecretKey());
         $charge = Customer::create($model->toUnsafeArray());
         $model->replace($charge->__toArray(true));
     } catch (Error\Card $e) {
         $model->replace($e->getJsonBody());
     }
 }
示例#5
0
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request CreateCharge */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     if (false == ($model['card'] || $model['customer'])) {
         throw new LogicException('The either card token or customer id has to be set.');
     }
     if (is_array($model['card'])) {
         throw new LogicException('The token has already been used.');
     }
     try {
         Stripe::setApiKey($this->keys->getSecretKey());
         $charge = Charge::create($model->toUnsafeArrayWithoutLocal());
         $model->replace($charge->__toArray(true));
     } catch (Error\Base $e) {
         $model->replace($e->getJsonBody());
     }
 }
示例#6
0
 /**
  * @test
  */
 public function shouldAllowGetSecretKeySetInConstructor()
 {
     $keys = new Keys('aPublishableKey', 'theSecretKey');
     $this->assertEquals('theSecretKey', $keys->getSecretKey());
 }