getState() public method

The state of the payment, authorization, or order transaction. The value is:
  • created. The transaction was successfully created.
  • approved. The buyer approved the transaction.
  • failed. The transaction request failed.
public getState ( ) : string
return string
 /**
  * @depends testSerializationDeserialization
  * @param Payment $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getId(), "TestSample");
     $this->assertEquals($obj->getIntent(), "TestSample");
     $this->assertEquals($obj->getPayer(), PayerTest::getObject());
     $this->assertEquals($obj->getPayee(), PayeeTest::getObject());
     $this->assertEquals($obj->getCart(), "TestSample");
     $this->assertEquals($obj->getTransactions(), TransactionTest::getObject());
     $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject());
     $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject());
     $this->assertEquals($obj->getState(), "TestSample");
     $this->assertEquals($obj->getExperienceProfileId(), "TestSample");
     $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject());
     $this->assertEquals($obj->getCreateTime(), "TestSample");
     $this->assertEquals($obj->getUpdateTime(), "TestSample");
     $this->assertEquals($obj->getLinks(), LinksTest::getObject());
 }
Exemplo n.º 2
0
 /**
  * @depends testSerializationDeserialization
  * @param Payment $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getId(), "TestSample");
     $this->assertEquals($obj->getIntent(), "TestSample");
     $this->assertEquals($obj->getPayer(), PayerTest::getObject());
     $this->assertEquals($obj->getPotentialPayerInfo(), PotentialPayerInfoTest::getObject());
     $this->assertEquals($obj->getPayee(), PayeeTest::getObject());
     $this->assertEquals($obj->getCart(), "TestSample");
     $this->assertEquals($obj->getTransactions(), array(TransactionTest::getObject()));
     $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject());
     $this->assertEquals($obj->getBillingAgreementTokens(), array("TestSample"));
     $this->assertEquals($obj->getCreditFinancingOffered(), CreditFinancingOfferedTest::getObject());
     $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject());
     $this->assertEquals($obj->getState(), "TestSample");
     $this->assertEquals($obj->getExperienceProfileId(), "TestSample");
     $this->assertEquals($obj->getNoteToPayer(), "TestSample");
     $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject());
     $this->assertEquals($obj->getFailureReason(), "TestSample");
     $this->assertEquals($obj->getCreateTime(), "TestSample");
     $this->assertEquals($obj->getUpdateTime(), "TestSample");
     $this->assertEquals($obj->getLinks(), LinksTest::getObject());
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function processPayment(PaymentInterface $payment) : PaymentInterface
 {
     $order = $payment->getOrder();
     $payer = $this->createPayer('paypal');
     $redirectUrls = $this->createRedirectUrls($payment);
     $transaction = $this->createTransaction($order);
     $payPalPayment = new Payment();
     $payPalPayment->setIntent("sale");
     $payPalPayment->setPayer($payer);
     $payPalPayment->setRedirectUrls($redirectUrls);
     $payPalPayment->setTransactions([$transaction]);
     try {
         $payPalPayment->create($apiContext);
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
     $payment->setApprovalUrl($payPalPayment->getApprovalLink());
     $payment->setState($payPalPayment->getState());
     $payment->setToken($payPalPayment->getId());
     $this->paymentManager->updateResource($payment);
     return $payment;
 }
 /**
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _prePayment($data)
 {
     $this->_autoload();
     $order = $this->_getOrder($data['order_number']);
     //initialise application
     $app = JFactory::getApplication();
     //get card input
     $data['cardtype'] = $app->input->getString("cardtype");
     $data['cardnum'] = $app->input->getString("cardnum");
     $month = $app->input->getString("month");
     $year = $app->input->getString("year");
     $card_exp = $month . '' . $year;
     $data['cardexp'] = $card_exp;
     $data['cardcvv'] = $app->input->getString("cardcvv");
     $data['cardnum_last4'] = substr($app->input->getString("cardnum"), -4);
     //initialise payment
     $apiContext = new ApiContext(new OAuthTokenCredential($this->api_clientId, $this->api_clientSecret));
     $apiContext->setConfig(array('mode' => $this->api_mode));
     //		echo'<pre>';print_r($apiContext);die;
     $card = new CreditCard();
     $card->setType($data['cardtype']);
     $card->setNumber($data['cardnum']);
     $card->setExpireMonth($month);
     $card->setExpireYear($year);
     $card->setFirstName($data['firstname']);
     $card->setLastName($data['lastname']);
     $card->setCvv2($data['cardcvv']);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     if (!empty($data['email'])) {
         $payerInfo = new PayerInfo();
         $payerInfo->setFirstName($data['firstname']);
         $payerInfo->setLastName($data['lastname']);
         $payerInfo->setEmail($data['email']);
         $payer->setPayerInfo($payerInfo);
     }
     $amount = new Amount();
     $amount->setCurrency($this->currency);
     $amount->setTotal($data['total']);
     $item1 = new Item();
     $item1->setName($data['order_number'])->setDescription($data['order_number'])->setCurrency($this->currency)->setQuantity(1)->setTax(0)->setPrice($data['total']);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setItemList($itemList);
     $transaction->setDescription($data['order_number']);
     $payment = new Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         $error = json_decode($ex->getData());
         $error_html = '<h2>' . $error->name . '</h2><br>';
         foreach ($error->details as $r) {
             $error_html .= '- ' . $r->field . ' - ' . $r->issue . '<br>';
         }
         $app->enqueueMessage($error_html, 'error');
         $app->redirect('index.php?option=com_bookpro&view=formpayment&order_id=' . $order->id . '&' . JSession::getFormToken() . '=1');
         return;
     } catch (Exception $ex) {
         die($ex);
     }
     $ack = $payment->getState();
     if ($ack == 'approved' || $ack == 'completed') {
         $order->pay_status = "SUCCESS";
         $order->order_status = "CONFIRMED";
         $order->tx_id = $payment->getId();
         $order->store();
     } else {
         JLog::addLogger(array('text_file' => 'paypal.txt', 'text_file_path' => 'logs', 'text_file_no_php' => 1, 'text_entry_format' => '{DATE} {TIME} {MESSAGE}'), JLog::ALERT);
         JLog::add('Transaction: ' . json_encode($payment) . '\\nOrder: ' . $order->order_number . ' Status: ' . $ack, JLog::ALERT, 'com_bookpro');
         $order->pay_status = "PENDING";
         $order->tx_id = $transaction_id;
         $order->store();
     }
     $app = JFactory::getApplication();
     $app->redirect('index.php?option=com_bookpro&controller=payment&task=postpayment&method=' . $this->_element . '&order_number=' . $order->order_number);
     return;
 }
Exemplo n.º 5
0
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
try {
    $payment->create($apiContext);
} catch (Exception $ex) {
    $status = 'error';
    if ($date < $today) {
        $status = 'declined';
    }
    error_log($ex);
}
/*
possible PayPal payment states: created, approved, failed, cancelled, expired
paydunk status - must be "success", "cancelled", or "error" depending on the outcome of your transaction.
*/
if ($payment->getState() == 'approved') {
    $status = 'success';
    //the payment was approved!
    //do some stuff here - update your order database, etc.
}
if ($payment->getState() == 'failed' || $payment->getState() == 'expired') {
    $status = 'error';
    //the payment failed to process
    //do some stuff here - update your order database, etc.
}
//set data for PUT request
$bodyparams = array("client_id" => "AEGbEsLu4cWjlQ8YfCC1bzI3Axq7UZ9k5gk7Y7yj", "client_secret" => "CMHBwkFvtNTFs0E06c1JHeHjuTShauMGDL1vRYUU", "status" => $status);
//sends the PUT request to the Paydunk API
function CallAPI($method, $url, $data = false)
{
    $curl = curl_init();
Exemplo n.º 6
0
 public function getLinkCheckOut($params = null)
 {
     if (!$params) {
         return false;
     }
     /*Payer
     	 A resource representing a Payer that funds a payment
     	 For paypal account payments, set payment method
     	 to 'paypal'.
     	 */
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $itemList = new ItemList();
     // Item must be a array and has one or more item.
     if (!$params['items']) {
         return false;
     }
     $arrItem = [];
     foreach ($params['items'] as $key => $item) {
         $it = new Item();
         $it->setName($item['name'])->setCurrency($params['currency'])->setQuantity($item['quantity'])->setPrice($item['price']);
         $arrItem[] = $it;
     }
     $itemList->setItems($arrItem);
     $amount = new Amount();
     $amount->setCurrency($params['currency'])->setTotal($params['total_price']);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($params['description']);
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     $redirectUrls = new RedirectUrls();
     $baseUrl = $this->getBaseUrl();
     $redirectUrls->setReturnUrl($baseUrl . $this->successUrl)->setCancelUrl($baseUrl . $this->cancelUrl);
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to 'sale'
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
     // ### Create Payment
     // Create a payment by calling the 'create' method
     // passing it a valid apiContext.
     try {
         $payment->create($this->config);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         throw new \DataErrorException($ex->getData(), $ex->getMessage());
     }
     // ### Get redirect url
     $redirectUrl = $payment->getApprovalLink();
     return ['payment_id' => $payment->getId(), 'status' => $payment->getState(), 'redirect_url' => $redirectUrl, 'description' => $transaction->getDescription()];
 }
Exemplo n.º 7
0
 public function createPayment($orderid, $userid)
 {
     if ($orderid > 0) {
         $orderid = (int) $orderid;
         $paypalCredentials = $this->getPaypalCredentials();
         $apiContext = new ApiContext(new OAuthTokenCredential($paypalCredentials["clientid"], $paypalCredentials["secret"]));
         $apiContext->setConfig($this->paypalConfig);
         $payer = new Payer();
         $payer->setPayment_method("paypal");
         $order = new Orders();
         $orderdetail = $order->getOrderDetail($orderid);
         //Setting up items for the paypal order detail
         //On future version this will have multiple packages based on cart content
         //When items were added api were responding abnormal
         /*
         $item = new Item();
         $item->setName($orderdetail["title"]);
         $item->setCurrency($orderdetail["currency"]);
         $item->setQuantity($orderdetail["quantity"]);
         $item->setPrice($orderdetail["package_price"]);
         $item->setSku($orderdetail["package_guid"]);
         $itemList = new ItemList();
         $itemList->setItems(array($item));
         */
         $amount = new Amount();
         $amount->setCurrency($orderdetail["currency"]);
         $amount->setTotal($orderdetail["total"]);
         $orderDescription = "Qty: " . $orderdetail["quantity"] . " for " . $orderdetail["title"] . " - " . $orderdetail["title_summary"];
         $transaction = new Transaction();
         $transaction->setDescription($orderDescription);
         $transaction->setAmount($amount);
         //$transaction->setItemlist($itemList);
         $redirectUrls = new RedirectUrls();
         $humanorderid = $order->getHumanOrderId($orderid);
         $redirectUrls->setReturn_url($paypalCredentials["returnurl"] . "&orderid=" . $humanorderid);
         $redirectUrls->setCancel_url($paypalCredentials["cancelurl"] . "&orderid=" . $humanorderid);
         $payment = new Payment();
         $payment->setIntent("sale");
         $payment->setPayer($payer);
         $payment->setRedirect_urls($redirectUrls);
         $payment->setTransactions(array($transaction));
         try {
             $payment->create($apiContext);
             $this->setPaypalInfoOrder($orderid, $payment->getId(), $payment->getCreateTime(), $payment->getUpdateTime(), $payment->getState(), $userid);
             // Retrieve buyer approval url from the `payment` object.
             foreach ($payment->getLinks() as $link) {
                 if ($link->getRel() == 'approval_url') {
                     $approvalUrl = $link->getHref();
                 }
             }
             $result = array("status" => true, "approval_url" => $approvalUrl);
             return $result;
         } catch (PayPal\Exception\PPConnectionException $ex) {
             //Logging error
             $this->log->addError($ex->getMessage() . LOG_LINESEPARATOR . "TRACE: " . $ex->getTraceAsString() . LOG_LINESEPARATOR);
             $result = array("status" => false, "approval_url" => "");
             return $result;
         }
     } else {
         //Logging error
         $this->log->addWarning("Invalid or null order id." . LOG_LINESEPARATOR);
         $result = array("status" => false, "approval_url" => "");
         return $result;
     }
 }
Exemplo n.º 8
0
 private static function _getStatus(\PayPal\Api\Payment &$payment)
 {
     return $payment->getState();
 }
Exemplo n.º 9
0
 public function initializePayment(PaymentInterface $payment)
 {
     $order = $payment->getOrder();
     $paymentMethod = $order->getPaymentMethod();
     $configuration = $paymentMethod->getConfiguration();
     $payPalType = $configuration['paypal_type'];
     if ($payPalType === 'paypal') {
         $apiContext = $this->getApiContext($configuration);
         $payer = $this->createPayer($payPalType);
         $redirectUrls = $this->createRedirectUrls($payment);
         $transaction = $this->createTransaction($order);
         $payPalPayment = new Payment();
         $payPalPayment->setIntent("sale");
         $payPalPayment->setPayer($payer);
         $payPalPayment->setRedirectUrls($redirectUrls);
         $payPalPayment->setTransactions([$transaction]);
         try {
             $payPalPayment->create($apiContext);
         } catch (PayPalConnectionException $e) {
             throw $e;
         }
         $payment->setRedirectUrl($payPalPayment->getApprovalLink());
         $payment->setState($payPalPayment->getState());
         $payment->setExternalIdentifier($payPalPayment->getId());
     }
     return $payment;
 }