From 5a3b0ac2b8bff1a8d78e59c554982953442b909b Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 30 Oct 2014 17:13:15 +0200 Subject: [PATCH] add docs. --- docs/get-it-started.md | 92 +++++++++++++++++++++++++++++++++ docs/index.md | 4 ++ docs/payment-done-controller.md | 40 ++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 docs/get-it-started.md create mode 100644 docs/index.md create mode 100644 docs/payment-done-controller.md diff --git a/docs/get-it-started.md b/docs/get-it-started.md new file mode 100644 index 0000000..1dc0142 --- /dev/null +++ b/docs/get-it-started.md @@ -0,0 +1,92 @@ +# Get it started. + +In this chapter we are going to setup payum package and do simple purchase using paypal express checkout. +Look at sandbox to find more examples. + +## Installation + +```bash +php composer.phar require "payum/payum-silex-provider:*@stable" "payum/xxx:*@stable" +``` + +_**Note**: Where payum/xxx is a payum package, for example it could be payum/paypal-express-checkout-nvp. Look at [supported payments](https://github.com/Payum/Core/blob/master/Resources/docs/supported-payments.md) to find out what you can use._ + +_**Note**: Use payum/payum if you want to install all payments at once._ + +Now you have all codes prepared and ready to be used. + +## Configuration + +First add PayumProvider to your application: + +```php +register(new \Payum\Silex\PayumProvider()); +``` + +Now you can configure the payment gateway and the storages: + +```php +share(function($app) { + return new FilesystemStorage('/path/to/storage', 'Payum\Core\Model\Token', 'hash'), +}); + +$app['payum.payments'] = $app->share($app->extend('payum.payments', function ($payments) use ($app) { + $payments['paypal_ec'] = PaypalPaymentFactory::create(new Api(array( + 'username' => 'EDIT_ME', + 'password' => 'EDIT_ME', + 'signature' => 'EDIT_ME', + 'sandbox' => true + ))); + + return $payments; +}); + +$app['payum.storages'] = $app->share($app->extend('payum.payments', function ($storages) use ($app) { + $storages['Payum\Core\Model\Order'] = new FilesystemStorage('path/to/storage', 'Payum\Core\Model\Order'); + + return $storages; +}); +``` + +## Prepare payment + +Lets create a controller where we prepare the payment details. + +```php +app = $app; + } + + public function preparePaypalAction() + { + $storage = $this->app['payum']->getStorage('Payum\Core\Model\Order'); + + $order = $storage->createModel(); + $order->setTotalAmount(123); + $order->setCurrencyCode('USD'); + $storage->updateModel($details); + + $captureToken = $this->app['payum.security.token_factory']->createCaptureToken('paypal_ec', $order, 'payment_done'); + + return new RedirectResponse($captureToken->getTargetUrl()); + } +} +``` + +Here's you may want to modify a `payment_done` route. +It is a controller where the a payer will be redirected after the payment is done, whenever it is success failed or pending. +Read a [dedicated chapter](payment-done-controller.md) about how the payment done controller may look like. + +Back to [index](index.md). \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..479b83a --- /dev/null +++ b/docs/index.md @@ -0,0 +1,4 @@ +# PayumSilexProvider + +* [Get it started](get-it-started.md) +* [Payment done controller](payment-done-controller.md) \ No newline at end of file diff --git a/docs/payment-done-controller.md b/docs/payment-done-controller.md new file mode 100644 index 0000000..bba0673 --- /dev/null +++ b/docs/payment-done-controller.md @@ -0,0 +1,40 @@ +# Payment done controller + +First we have to validate the request. +If it is valid the verifier returns a token. +We can use it later to get payment status, details and any other information. + +```php +app = $app; + } + + public function done(Request $request) + { + $token = $this->app['payum.security.http_request_verifier']->verify($request); + + $payment = $this->app['payum']->getPayment($token->getPaymentName()); + + $payment->execute($status = new GetHumanStatus($token)); + + return new JsonResponse(array( + 'status' => $status->getValue(), + 'details' => $status->getModel()->getDetails() + )); + } +} +``` + +Back to [index](index.md). \ No newline at end of file