Example #1
0
 /**
  * execute payment
  *
  * @param OnlineShop_Framework_IPrice $price
  * @param string                      $reference
  *
  * @return OnlineShop_Framework_Payment_IStatus
  */
 public function executeDebit(OnlineShop_Framework_IPrice $price = null, $reference = null)
 {
     // Execute payment
     $x = new stdClass();
     $x->DoExpressCheckoutPaymentRequest = new stdClass();
     $x->DoExpressCheckoutPaymentRequest->Version = $this->protocol;
     $x->DoExpressCheckoutPaymentRequest->DoExpressCheckoutPaymentRequestDetails = new stdClass();
     $x->DoExpressCheckoutPaymentRequest->DoExpressCheckoutPaymentRequestDetails->Token = $this->authorizedData['token'];
     $x->DoExpressCheckoutPaymentRequest->DoExpressCheckoutPaymentRequestDetails->PayerID = $this->authorizedData['PayerID'];
     $x->DoExpressCheckoutPaymentRequest->DoExpressCheckoutPaymentRequestDetails->PaymentDetails = $this->createPaymentDetails($price);
     // execute
     $ret = $this->client->DoExpressCheckoutPayment($x);
     // check Ack
     if ($ret->Ack == 'Success' || $ret->Ack == 'SuccessWithWarning') {
         // success
         $paymentInfo = $ret->DoExpressCheckoutPaymentResponseDetails->PaymentInfo;
         return new OnlineShop_Framework_Impl_Payment_Status($reference, $paymentInfo->TransactionID, null, OnlineShop_Framework_AbstractOrder::ORDER_STATE_COMMITTED, ['paypal_TransactionType' => $paymentInfo->TransactionType, 'paypal_PaymentType' => $paymentInfo->PaymentType, 'paypal_amount' => (string) $price]);
     } else {
         // failed
         $message = '';
         $errors = is_array($ret->Errors) ? $ret->Errors : array($ret->Errors);
         foreach ($errors as $error) {
             $message .= $error->LongMessage . "\n";
         }
         return new OnlineShop_Framework_Impl_Payment_Status($reference, $ret->CorrelationID, $message, OnlineShop_Framework_AbstractOrder::ORDER_STATE_ABORTED);
     }
 }