public function testRequestGetExpressCheckoutDetails() { $response = $this->client->requestSetExpressCheckout('123', 'http://www.foo.com/', 'http://www.foo.com/'); //guard $this->assertInstanceOf('JMS\\Payment\\PaypalBundle\\Client\\Response', $response); $this->assertTrue($response->body->has('TOKEN')); $response = $this->client->requestGetExpressCheckoutDetails($response->body->get('TOKEN')); $this->assertTrue($response->body->has('TOKEN')); $this->assertTrue($response->body->has('CHECKOUTSTATUS')); $this->assertEquals('PaymentActionNotInitiated', $response->body->get('CHECKOUTSTATUS')); $this->assertEquals('Success', $response->body->get('ACK')); }
protected function createCheckoutBillingAgreement(FinancialTransactionInterface $transaction, $paymentAction) { $data = $transaction->getExtendedData(); $token = $this->obtainExpressCheckoutToken($transaction, $paymentAction); $details = $this->client->requestGetExpressCheckoutDetails($token); $this->throwUnlessSuccessResponse($details, $transaction); // verify checkout status switch ($details->body->get('CHECKOUTSTATUS')) { case 'PaymentActionFailed': $ex = new FinancialException('PaymentAction failed.'); $transaction->setResponseCode('Failed'); $transaction->setReasonCode('PaymentActionFailed'); $ex->setFinancialTransaction($transaction); throw $ex; case 'PaymentCompleted': break; case 'PaymentActionNotInitiated': break; default: $actionRequest = new ActionRequiredException('User has not yet authorized the transaction.'); $actionRequest->setFinancialTransaction($transaction); $actionRequest->setAction(new VisitUrl($this->client->getAuthenticateExpressCheckoutTokenUrl($token))); throw $actionRequest; } // complete the transaction $data->set('paypal_payer_id', $details->body->get('PAYERID')); $optionalParameters = array('PAYMENTREQUEST_0_CURRENCYCODE' => $transaction->getPayment()->getPaymentInstruction()->getCurrency()); if (null !== ($notifyUrl = $this->getNotifyUrl($data))) { $optionalParameters['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyUrl; } $response = $this->client->requestDoExpressCheckoutPayment($data->get('express_checkout_token'), $transaction->getRequestedAmount(), $paymentAction, $details->body->get('PAYERID'), $optionalParameters); $this->throwUnlessSuccessResponse($response, $transaction); switch ($response->body->get('PAYMENTINFO_0_PAYMENTSTATUS')) { case 'Completed': break; case 'Pending': $transaction->setReferenceNumber($response->body->get('PAYMENTINFO_0_TRANSACTIONID')); throw new PaymentPendingException('Payment is still pending: ' . $response->body->get('PAYMENTINFO_0_PENDINGREASON')); default: $ex = new FinancialException('PaymentStatus is not completed: ' . $response->body->get('PAYMENTINFO_0_PAYMENTSTATUS')); $ex->setFinancialTransaction($transaction); $transaction->setResponseCode('Failed'); $transaction->setReasonCode($response->body->get('PAYMENTINFO_0_PAYMENTSTATUS')); throw $ex; } $transaction->setReferenceNumber($response->body->get('PAYMENTINFO_0_TRANSACTIONID')); $transaction->setProcessedAmount($response->body->get('PAYMENTINFO_0_AMT')); $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS); $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS); }