setTotal() 공개 메소드

Total amount charged from the payer to the payee. In case of a refund, this is the refunded amount to the original payer from the payee. 10 characters max with support for 2 decimal places.
public setTotal ( string | double $total )
$total string | double
예제 #1
0
 /**
  * @group integration
  */
 public function testOperations()
 {
     try {
         $authId = AuthorizationTest::authorize();
         $auth = Authorization::get($authId);
         $amount = new Amount();
         $amount->setCurrency("USD");
         $amount->setTotal("1.00");
         $captr = new Capture();
         $captr->setId($authId);
         $captr->setAmount($amount);
         $capt = $auth->capture($captr);
         $captureId = $capt->getId();
         $this->assertNotNull($captureId);
         $refund = new Refund();
         $refund->setId($captureId);
         $refund->setAmount($amount);
         $capture = Capture::get($captureId);
         $this->assertNotNull($capture->getId());
         $retund = $capture->refund($refund);
         $this->assertNotNull($retund->getId());
     } catch (PayPalConnectionException $ex) {
         $this->markTestSkipped('Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage());
     }
 }
예제 #2
0
 /**
  * @param PaymentInterface $payment
  */
 public function init(PaymentInterface $payment)
 {
     $credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
     $apiContext = new ApiContext($credentials);
     $apiContext->setConfig(['mode' => $this->options['mode']]);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $amount = new Amount();
     $amount->setCurrency($this->options['currency']);
     $amount->setTotal($payment->getPaymentSum());
     $item = new Item();
     $item->setName($payment->getDescription());
     $item->setCurrency($amount->getCurrency());
     $item->setQuantity(1);
     $item->setPrice($amount->getTotal());
     $itemList = new ItemList();
     $itemList->addItem($item);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($payment->getDescription());
     $transaction->setItemList($itemList);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($payment->getExtraData('return_url'));
     $redirectUrls->setCancelUrl($payment->getExtraData('cancel_url'));
     $paypalPayment = new Payment();
     $paypalPayment->setIntent('sale');
     $paypalPayment->setPayer($payer);
     $paypalPayment->setTransactions([$transaction]);
     $paypalPayment->setRedirectUrls($redirectUrls);
     $paypalPayment->create($apiContext);
     $payment->setExtraData('paypal_payment_id', $paypalPayment->getId());
     $payment->setExtraData('approval_link', $paypalPayment->getApprovalLink());
 }
예제 #3
0
 public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl)
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     // specify the payment ammount
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($paymentDesc);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($returnUrl . '&success=true');
     $redirectUrls->setCancelUrl($returnUrl . '&success=false');
     $payment = new Payment();
     $payment->setRedirectUrls($redirectUrls);
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     try {
         $payment->create($this->apiContext);
     } catch (Exception $e) {
         throw new Exception($e);
     }
     return $payment;
 }
예제 #4
0
파일: paypal.php 프로젝트: fur81/zofaxiopeu
/**
 * Create a payment using a previously obtained
 * credit card id. The corresponding credit
 * card is used as the funding instrument.
 * 
 * @param string $creditCardId credit card id
 * @param string $total Payment amount with 2 decimal points
 * @param string $currency 3 letter ISO code for currency
 * @param string $paymentDesc
 */
function makePaymentUsingCC($creditCardId, $total, $currency, $paymentDesc)
{
    $ccToken = new CreditCardToken();
    $ccToken->setCreditCardId($creditCardId);
    $fi = new FundingInstrument();
    $fi->setCreditCardToken($ccToken);
    $payer = new Payer();
    $payer->setPaymentMethod("credit_card");
    $payer->setFundingInstruments(array($fi));
    // Specify the payment amount.
    $amount = new Amount();
    $amount->setCurrency($currency);
    $amount->setTotal($total);
    // ###Transaction
    // A transaction defines the contract of a
    // payment - what is the payment for and who
    // is fulfilling it. Transaction is created with
    // a `Payee` and `Amount` types
    $transaction = new Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription($paymentDesc);
    $payment = new Payment();
    $payment->setIntent("sale");
    $payment->setPayer($payer);
    $payment->setTransactions(array($transaction));
    $payment->create(getApiContext());
    return $payment;
}
예제 #5
0
 public static function createAmount()
 {
     $amount = new Amount();
     $amount->setCurrency(self::$currency);
     $amount->setTotal(self::$total);
     return $amount;
 }
예제 #6
0
 /**
  * @param string $currency
  * @param int $total
  * @param Details $details
  *
  * @return Amount
  */
 public static function createAmount(Details $details, $total, $currency)
 {
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     $amount->setDetails($details);
     return $amount;
 }
 /**
  * Creates an amount definition for given order
  *
  * @param OrderInterface $order
  *
  * @return Amount
  */
 protected function createAmount(OrderInterface $order) : Amount
 {
     $details = $this->createDetails($order);
     $amount = new Amount();
     $amount->setCurrency($order->getCurrency());
     $amount->setTotal($order->getOrderTotal()->getGrossAmount());
     $amount->setDetails($details);
     return $amount;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('ATGFkB2ea6f0pM92jwBqkZ17kxsiftDvUhLHyXson-10AUs7n5TocpEc0sis7Cl_fMIxS8uQO04kPP8Q', 'ENP_JPkc3e4Yl6VeHZ_0vgvEh0SYdtzkMvw_VGBrr2nJ67sg9RuKB_YF7y_k4bj-4t2U-_23MaAGV3vD'));
     $status = '';
     if (isset($_GET['success']) && $_GET['success'] == 'true') {
         $transaction = new Transaction();
         $amount = new Amount();
         $paymentId = $_GET['paymentId'];
         $payment = Payment::get($paymentId, $apiContext);
         $amount->setCurrency($payment->transactions[0]->amount->getCurrency());
         $amount->setTotal($payment->transactions[0]->amount->getTotal());
         $amount->setDetails($payment->transactions[0]->amount->getDetails());
         $transaction->setAmount($amount);
         $execution = new PaymentExecution();
         $execution->setPayerId($_GET['PayerID']);
         $execution->addTransaction($transaction);
         $rifas = $payment->transactions[0]->description;
         $rifas = explode(',', $rifas);
         $aux = 0;
         try {
             foreach ($rifas as $rifa) {
                 $aux = Rifa::find($rifa);
                 if ($aux->user_id == NULL) {
                     $aux->user_id = Auth::user()->id;
                     $aux->save();
                 } else {
                     $status = 'Numeros de rifas ja foram escolhidos por outra pessoa, por favor escolha novamente.';
                     return view('confirmacao')->with('status', $status);
                 }
             }
             $result = $payment->execute($execution, $apiContext);
             try {
                 $payment = Payment::get($paymentId, $apiContext);
             } catch (Exception $ex) {
                 $status = 'Pagamento ainda sem confirmacao';
             }
         } catch (Exception $ex) {
             $status = 'Compra nao foi executada';
         }
         if ($result->state == "approved") {
             $status = 'Compra feita com sucesso!';
             $aux = 1;
         }
         return view('confirmacao')->with('status', $status)->with('aux', $aux);
     } else {
         $status = 'Compra cancelada pelo usuario';
         return view('confirmacao')->with('status', $status);
     }
 }
예제 #9
0
 function paypal($data)
 {
     try {
         foreach ($data as $k => $v) {
             ${$k} = $v;
         }
         include_once 'config.paypal.php';
         $apiContext = new ApiContext(new OAuthTokenCredential(CLIENT_ID, CLIENT_SECRET));
         list($m, $y) = explode("/", $card_expiry);
         $card = new CreditCard();
         $card->setNumber($card_number);
         $card->setType(strtolower($card_type));
         $card->setExpireMonth($m);
         $card->setExpireYear($y);
         $card->setCvv2($card_cvv);
         $card->setFirstName($first_name);
         $card->setLastName($last_name);
         $fi = new FundingInstrument();
         $fi->setCreditCard($card);
         $payer = new Payer();
         $payer->setPaymentMethod('credit_card');
         $payer->setFundingInstruments(array($fi));
         $amount = new Amount();
         $amount->setCurrency($currency);
         $amount->setTotal($price);
         $transaction = new Transaction();
         $transaction->setAmount($amount);
         $transaction->setDescription('Enter your card details and proceed');
         $payment = new Payment();
         $payment->setIntent('sale');
         $payment->setPayer($payer);
         $payment->setTransactions(array($transaction));
         $res = json_decode($payment->create($apiContext));
         $this->save($data, __FUNCTION__, $res, 1);
         return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $res->state)]);
     } catch (Exception $e) {
         if ($e instanceof PPConfigurationException) {
         } elseif ($e instanceof PPConnectionException) {
         } elseif ($e instanceof PayPal\Exception\PayPalConnectionException) {
             $res = json_decode($e->getData(), 1);
             $this->save($data, __FUNCTION__, $res, 0);
             $msg = array_shift(isset($res["details"]) ? $res["details"] : []);
             return json_encode(["status" => false, "msg" => $res["name"] == "UNKNOWN_ERROR" || empty($msg["issue"]) ? "An unknown error has occurred" : sprintf("%s %s", ["cvv2" => "CVV2", "expire_year" => "Card expiration", "credit_card" => "", "type" => "Invalid credit card number or", "number" => "Credit card number", "expire_month" => "Expiration month"][end(explode(".", $msg["field"]))], strtolower($msg["issue"]))]);
         } else {
             throw $e;
         }
     }
 }
예제 #10
0
 /**
  * @return array array of PayPal\Api\Transaction
  */
 protected function getTransactions()
 {
     $payPalItems = array();
     $currency = $this->currency ? $this->currency : $this->context->getCurrency();
     $payPalItem = new Item();
     $payPalItem->setName($this->name);
     $payPalItem->setCurrency($currency);
     $payPalItem->setQuantity($this->quantity);
     $payPalItem->setPrice($this->price);
     $payPalItems[] = $payPalItem;
     $totalPrice = $this->quantity * $this->price;
     $itemLists = new ItemList();
     $itemLists->setItems($payPalItems);
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($totalPrice);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setItemList($itemLists);
     return array($transaction);
 }
예제 #11
0
 public function testOperations()
 {
     $authId = AuthorizationTest::authorize();
     $auth = Authorization::get($authId);
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $captr = new Capture();
     $captr->setId($authId);
     $captr->setAmount($amount);
     $capt = $auth->capture($captr);
     $captureId = $capt->getId();
     $this->assertNotNull($captureId);
     $refund = new Refund();
     $refund->setId($captureId);
     $refund->setAmount($amount);
     $capture = Capture::get($captureId);
     $this->assertNotNull($capture->getId());
     $retund = $capture->refund($refund);
     $this->assertNotNull($retund->getId());
 }
예제 #12
0
파일: Paypal.php 프로젝트: app-zap/payment
 /**
  * When you have configured the payment properly this will give you a URL that you can redirect your visitor to,
  * so that he can pay the desired amount.
  *
  * @param string $url_format
  * @return string
  */
 public function get_payment_url($url_format)
 {
     if (!is_array($this->payment_provider_auth_config[self::PROVIDER_NAME]) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid']) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['secret'])) {
         throw new \Exception('Auth Config for Provider ' . self::PROVIDER_NAME . ' is not set.', 1394795187);
     }
     $total_price = $this->order->get_total_price();
     if ($total_price == 0) {
         throw new \Exception('Total price is 0. Provider ' . self::PROVIDER_NAME . ' does not support free payments.', 1394795478);
     }
     $api_context = new ApiContext(new OAuthTokenCredential($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid'], $this->payment_provider_auth_config[self::PROVIDER_NAME]['secret']));
     $api_context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => false));
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $amount = new Amount();
     $amount->setCurrency("EUR");
     $amount->setTotal($this->order->get_total_price());
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($this->order->get_reason());
     $transaction->setItemList($this->getItemList());
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($this->get_success_url($url_format));
     $redirectUrls->setCancelUrl($this->get_abort_url($url_format));
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $payment->create($api_context);
     $payment_url = '';
     foreach ($payment->getLinks() as $link) {
         /** @var \PayPal\Api\Links $link */
         if ($link->getRel() == 'approval_url') {
             $payment_url = $link->getHref();
         }
     }
     return $payment_url;
 }
예제 #13
0
function createAuthorization($apiContext)
{
    $addr = new Address();
    $addr->setLine1("3909 Witmer Road");
    $addr->setLine2("Niagara Falls");
    $addr->setCity("Niagara Falls");
    $addr->setState("NY");
    $addr->setPostal_code("14305");
    $addr->setCountry_code("US");
    $addr->setPhone("716-298-1822");
    $card = new CreditCard();
    $card->setType("visa");
    $card->setNumber("4417119669820331");
    $card->setExpire_month("11");
    $card->setExpire_year("2019");
    $card->setCvv2("012");
    $card->setFirst_name("Joe");
    $card->setLast_name("Shopper");
    $card->setBilling_address($addr);
    $fi = new FundingInstrument();
    $fi->setCredit_card($card);
    $payer = new Payer();
    $payer->setPayment_method("credit_card");
    $payer->setFunding_instruments(array($fi));
    $amount = new Amount();
    $amount->setCurrency("USD");
    $amount->setTotal("1.00");
    $transaction = new Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription("This is the payment description.");
    $payment = new Payment();
    $payment->setIntent("authorize");
    $payment->setPayer($payer);
    $payment->setTransactions(array($transaction));
    $paymnt = $payment->create($apiContext);
    $resArray = $paymnt->toArray();
    return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
예제 #14
0
 public function callCreate($clientId, $clientSecret, $orderId, $amount, $currency, $description, $returnUrl, $cancelUrl)
 {
     $oauthCredential = new OAuthTokenCredential($clientId, $clientSecret);
     $apiContext = new ApiContext($oauthCredential);
     $apiContext->setConfig(['mode' => $this->mode]);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item = new Item();
     $item->setName($description);
     $item->setCurrency($currency);
     $item->setPrice($amount);
     $item->setQuantity(1);
     $itemList = new ItemList();
     $itemList->setItems(array($item));
     $amountObject = new Amount();
     $amountObject->setCurrency($currency);
     $amountObject->setTotal($amount);
     $transaction = new Transaction();
     $transaction->setItemList($itemList);
     $transaction->setAmount($amountObject);
     $transaction->setDescription($description);
     $transaction->setInvoiceNumber($orderId);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl);
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     try {
         $payment->create($apiContext);
     } catch (\Exception $e) {
         throw new PaymentException('PayPal Exception: ' . $e->getMessage());
     }
     $approvalUrl = $payment->getApprovalLink();
     return $approvalUrl;
 }
예제 #15
0
 /**
  * Runs a payment with PayPal
  *
  * @link https://devtools-paypal.com/guide/pay_paypal/php?interactive=ON&env=sandbox
  * @return PayPal\Api\Payment 
  */
 public function payPaypal($urls = [], $sum = 0, $message = '')
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $amount = new Amount();
     $amount->setCurrency($this->currency);
     $amount->setTotal($sum);
     $transaction = new Transaction();
     if ($message) {
         $transaction->setDescription($message);
     }
     $transaction->setAmount($amount);
     $redirectUrls = new RedirectUrls();
     $return_url = isset($urls['return_url']) ? $urls['return_url'] : 'https://devtools-paypal.com/guide/pay_paypal/php?success=true';
     $cancel_url = isset($urls['cancel_url']) ? $urls['cancel_url'] : 'https://devtools-paypal.com/guide/pay_paypal/php?success=true';
     $redirectUrls->setReturnUrl($return_url);
     $redirectUrls->setCancelUrl($cancel_url);
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions([$transaction]);
     return $payment->create($this->_apiContext);
     // get approval url from this json
 }
예제 #16
0
// # Sale Refund Sample
// This sample code demonstrate how you can
// process a refund on a sale transaction created
// using the Payments API.
// API used: /v1/payments/sale/{sale-id}/refund
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Refund;
use PayPal\Api\Sale;
// ### Refund
// Create a refund object indicating
// refund amount
$amt = new Amount();
$amt->setCurrency('USD');
$amt->setTotal('0.01');
$refund = new Refund();
$refund->setAmount($amt);
$saleId = '3RM92092UW5126232';
// ###Sale
// A sale transaction.
// Create a Sale object with the
// given sale transaction id.
$sale = new Sale();
$sale->setId($saleId);
try {
    // Refund the sale
    // (See bootstrap.php for more on `ApiContext`)
    $sale->refund($refund, $apiContext);
} catch (\PPConnectionException $ex) {
    echo "Exception:" . $ex->getMessage() . PHP_EOL;
예제 #17
0
 public function testReauthorize()
 {
     $authorization = Authorization::get('7GH53639GA425732B');
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $authorization->setAmount($amount);
     try {
         $reauthorization = $authorization->reauthorize();
     } catch (PPConnectionException $ex) {
         $this->assertEquals(strpos($ex->getMessage(), "500"), false);
     }
 }
 /**
  * @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;
 }
예제 #19
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;
     }
 }
 public function teszt($amount, $description)
 {
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AfikH2WfU1x0YF1ThuSkBaMKqDh-rxE5NEBpLWOF3UVmii-P97WdgJCUhoH1ff5pMHToHnB-sXoejgGv', 'EM7ObD_onQ1EqaeiVBFvSId9AIQevTlsYcLPi-3SeVivyQ9A361Ov5jx4KlFkamOsh_c6I25VM1Ck4ZX'));
     //SAMPLE 1
     // $card = new CreditCard();
     // $card->setType("visa")
     //     ->setNumber("4148529247832259")
     //     ->setExpireMonth("11")
     //     ->setExpireYear("2019")
     //     ->setCvv2("012")
     //     ->setFirstName("Joe")
     //     ->setLastName("Shopper");
     // // ### FundingInstrument
     // // A resource representing a Payer's funding instrument.
     // // For direct credit card payments, set the CreditCard
     // // field on this object.
     // $fi = new FundingInstrument();
     // $fi->setCreditCard($card);
     // // ### Payer
     // // A resource representing a Payer that funds a payment
     // // For direct credit card payments, set payment method
     // // to 'credit_card' and add an array of funding instruments.
     // $payer = new Payer();
     // $payer->setPaymentMethod("credit_card")
     //     ->setFundingInstruments(array($fi));
     // // ### Itemized information
     // // (Optional) Lets you specify item wise
     // // information
     // $item1 = new Item();
     // $item1->setName('Ground Coffee 40 oz')
     //     ->setDescription('Ground Coffee 40 oz')
     //     ->setCurrency('USD')
     //     ->setQuantity(1)
     //     ->setTax(0.3)
     //     ->setPrice(7.50);
     // $item2 = new Item();
     // $item2->setName('Granola bars')
     //     ->setDescription('Granola Bars with Peanuts')
     //     ->setCurrency('USD')
     //     ->setQuantity(5)
     //     ->setTax(0.2)
     //     ->setPrice(2);
     // $itemList = new ItemList();
     // $itemList->setItems(array($item1, $item2));
     // // ### Additional payment details
     // // Use this optional field to set additional
     // // payment information such as tax, shipping
     // // charges etc.
     // $details = new Details();
     // $details->setShipping(1.2)
     //     ->setTax(1.3)
     //     ->setSubtotal(17.5);
     // // ### Amount
     // // Lets you specify a payment amount.
     // // You can also specify additional details
     // // such as shipping, tax.
     // $amount = new Amount();
     // $amount->setCurrency("USD")
     //     ->setTotal(20)
     //     ->setDetails($details);
     // // ### Transaction
     // // A transaction defines the contract of a
     // // payment - what is the payment for and who
     // // is fulfilling it.
     // $transaction = new Transaction();
     // $transaction->setAmount($amount)
     //     ->setItemList($itemList)
     //     ->setDescription("Payment description")
     //     ->setInvoiceNumber(uniqid());
     // // ### Payment
     // // A Payment Resource; create one using
     // // the above types and intent set to sale 'sale'
     // $payment = new Payment();
     // $payment->setIntent("sale")
     //     ->setPayer($payer)
     //     ->setTransactions(array($transaction));
     // // For Sample Purposes Only.
     // $request = clone $payment;
     // // ### Create Payment
     // // Create a payment by calling the payment->create() method
     // // with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
     // // The return object contains the state.
     // try {
     //     $payment->create($apiContext);
     // } catch (Exception $ex) {
     //    // ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex);
     //     exit(1);
     // }
     //ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
     //return $payment;
     //END SAMPLE 1
     //SAMPLE 2
     // $creditCard = new \PayPal\Api\CreditCard();
     // $creditCard->setType("visa")
     //     ->setNumber("4417119669820331")
     //     ->setExpireMonth("11")
     //     ->setExpireYear("2019")
     //     ->setCvv2("012")
     //     ->setFirstName("Joe")
     //     ->setLastName("Shopper");
     // try {
     //     $creditCard->create($apiContext);
     //     echo '<pre>';
     //     print_r($creditCard);
     // }
     // catch (\PayPal\Exception\PayPalConnectionException $ex) {
     //     echo $ex;
     // }
     //END SAMPLE 2
     //SAMPLE 3
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // ### Itemized information
     // (Optional) Lets you specify item wise
     // information
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     // ### Additional payment details
     // Use this optional field to set additional
     // payment information such as tax, shipping
     // charges etc.
     /* $details = new Details();
     $details->setShipping(1.2)
         ->setTax(1.3)
         ->setSubtotal(17.50); */
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     /* $amount = new Amount();
     $amount->setCurrency("USD")
         ->setTotal(20)
         ->setDetails($details); */
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it.
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description");
     // ->setInvoiceNumber('134');
     //>setInvoiceNumber(uniqid());
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     //$baseUrl = getBaseUrl();
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/ordered")->setCancelUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/index");
     // ### 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(array($transaction)); */
     $addr = new Address();
     $addr->setLine1('52 N Main ST');
     $addr->setCity('Johnstown');
     $addr->setCountryCode('US');
     $addr->setPostalCode('43210');
     $addr->setState('OH');
     $card = new CreditCard();
     $card->setNumber('5110929378020149');
     $card->setType('MASTERCARD');
     $card->setExpireMonth('08');
     $card->setExpireYear('2020');
     $card->setCvv2('874');
     $card->setFirstName('Nishanth');
     $card->setLastName('Pininti');
     $card->setBillingAddress($addr);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card');
     $payer->setFundingInstruments(array($fi));
     $amountDetails = new \PayPal\Api\Details();
     $amountDetails->setSubtotal('7.41');
     $amountDetails->setTax('0.03');
     $amountDetails->setShipping('0.03');
     $amount = new Amount();
     $amount->setCurrency('USD');
     $amount->setTotal('7.47');
     $amount->setDetails($amountDetails);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('This is the payment transaction description.');
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     // For Sample Purposes Only.
     $request = clone $payment;
     // ### Create Payment
     // Create a payment by calling the 'create' method
     // passing it a valid apiContext.
     // (See bootstrap.php for more on `ApiContext`)
     // The return object contains the state and the
     // url to which the buyer must be redirected to
     // for payment approval
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
         exit(1);
     }
     // ### Get redirect url
     // The API response provides the url that you must redirect
     // the buyer to. Retrieve the url from the $payment->getApprovalLink()
     // method
     //$approvalUrl = $payment->getRedirectUrls();
     // ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
     var_dump($payment);
     return $payment;
     //END SAMPLE 3
 }
예제 #21
0
파일: Paypalnew.php 프로젝트: ewwgit/eptri
 public function payDemo()
 {
     $this->authorize();
     $addr = new Address();
     $addr->setLine1('52 N Main ST');
     $addr->setCity('Johnstown');
     $addr->setCountryCode('US');
     $addr->setPostalCode('43210');
     $addr->setState('OH');
     $card = new CreditCard();
     $card->setNumber('4417119669820331');
     $card->setType('visa');
     $card->setExpireMonth('11');
     $card->setExpireYear('2018');
     $card->setCvv2('874');
     $card->setFirstName('Joe');
     $card->setLastName('Shopper');
     $card->setBillingAddress($addr);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card');
     $payer->setFundingInstruments(array($fi));
     $amountDetails = new \PayPal\Api\Details();
     $amountDetails->setSubtotal('7.41');
     $amountDetails->setTax('0.03');
     $amountDetails->setShipping('0.03');
     $amount = new Amount();
     $amount->setCurrency('USD');
     $amount->setTotal('7.47');
     $amount->setDetails($amountDetails);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('This is the payment transaction description.');
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create($this->_apiContext);
 }
예제 #22
0
 // PaymentExecution object includes information necessary
 // to execute a PayPal account payment.
 // The payer_id is added to the request query parameters
 // when the user is redirected from paypal back to your site
 $execution = new PaymentExecution();
 $execution->setPayerId($_GET['PayerID']);
 // ### Optional Changes to Amount
 // If you wish to update the amount that you wish to charge the customer,
 // based on the shipping address or any other reason, you could
 // do that by passing the transaction object with just `amount` field in it.
 // Here is the example on how we changed the shipping to $1 more than before.
 $transaction = new Transaction();
 $amount = new Amount();
 $details = new Details();
 $amount->setCurrency('USD');
 $amount->setTotal($payment->getTransactions()[0]->amount->total);
 $amount->setDetails($details);
 $transaction->setAmount($amount);
 // Add the above transaction object inside our Execution object.
 $execution->addTransaction($transaction);
 try {
     // Execute the payment
     // (See bootstrap.php for more on `ApiContext`)
     $result = $payment->execute($execution, $apiContext);
     // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
     //        ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result);
     try {
         $payment = Payment::get($paymentId, $apiContext);
     } catch (Exception $ex) {
         // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
         // 	        ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
예제 #23
0
파일: Paypal.php 프로젝트: shivap87/cost
 /**
  * Create a payment using the buyer's paypal
  * account as the funding instrument. Your app
  * will have to redirect the buyer to the paypal 
  * website, obtain their consent to the payment
  * and subsequently execute the payment using
  * the execute API call. 
  * 
  * @param string $total	payment amount in DDD.DD format
  * @param string $currency	3 letter ISO currency code such as 'USD'
  * @param string $paymentDesc	A description about the payment
  * @param string $returnUrl	The url to which the buyer must be redirected
  * 				to on successful completion of payment
  * @param string $cancelUrl	The url to which the buyer must be redirected
  * 				to if the payment is cancelled
  * @return \PayPal\Api\Payment
  */
 function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl)
 {
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // Specify the payment amount.
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $item = new Item();
     $item->setQuantity(1);
     $item->setName($paymentDesc);
     $item->setPrice($total);
     $item->setCurrency("USD");
     $itemList = new ItemList();
     $itemList->setItems(array($item));
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setItemList($itemList);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($returnUrl);
     $redirectUrls->setCancelUrl($cancelUrl);
     $payment = new Payment();
     $payment->setRedirectUrls($redirectUrls);
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create($this->getApiContext());
     return $payment;
 }
예제 #24
0
use PayPal\Api\Details;
use PayPal\Api\ExecutePayment;
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
if (isset($_GET['success']) && $_GET['success'] == 'true') {
    $paymentId = $_GET['paymentId'];
    $payment = Payment::get($paymentId, $api);
    $execution = new PaymentExecution();
    $execution->setPayerId($_GET['PayerID']);
    $transaction = new Transaction();
    $amount = new Amount();
    $details = new Details();
    $details->setShipping(2.2)->setTax(1.3)->setSubtotal(17.5);
    $amount->setCurrency('USD');
    $amount->setTotal(21);
    $amount->setDetails($details);
    $transaction->setAmount($amount);
    $execution->addTransaction($transaction);
    try {
        $result = $payment->execute($execution, $api);
        try {
            $payment = Payment::get($paymentId, $api);
            // ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result);
            echo 'Result Executed Payment';
        } catch (Exception $ex) {
            // ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
            echo 'Error GET PAYMENT';
            exit(1);
        }
    } catch (Exception $ex) {
<?php

// ##Reauthorization Sample
// This sample code demonstrates how you can reauthorize a PayPal
// account payment.
// API used: v1/payments/authorization/{authorization_id}/reauthorize
/** @var Authorization $authorization */
$authorization = (require 'AuthorizePayment.php');
use PayPal\Api\Authorization;
use PayPal\Api\Amount;
// ### Reauthorization
// Reauthorization is available only for PayPal account payments
// and not for credit card payments.
// You can reauthorize a payment only once 4 to 29
// days after the 3-day honor period for the original authorization
// has expired.
try {
    $amount = new Amount();
    $amount->setCurrency("USD");
    $amount->setTotal(1);
    // ### Reauthorize with amount being reauthorized
    $authorization->setAmount($amount);
    $reAuthorization = $authorization->reauthorize($apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization);
예제 #26
0
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
$fi = new FundingInstrument();
$fi->setCredit_card($card);
// ### Payer
// A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
$payer = new Payer();
$payer->setPayment_method("credit_card");
$payer->setFunding_instruments(array($fi));
// ### Amount
// Let's you specify a payment amount.
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
// ### Payment
// A Payment Resource; create one using
// the above types and intent as 'sale'
$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
 function get_approvalurl()
 {
     try {
         // try a payment request
         $PaymentData = AngellEYE_Gateway_Paypal::calculate(null, $this->send_items);
         $OrderItems = array();
         if ($this->send_items) {
             foreach ($PaymentData['order_items'] as $item) {
                 $_item = new Item();
                 $_item->setName($item['name'])->setCurrency(get_woocommerce_currency())->setQuantity($item['qty'])->setPrice($item['amt']);
                 array_push($OrderItems, $_item);
             }
         }
         $redirectUrls = new RedirectUrls();
         $redirectUrls->setReturnUrl(add_query_arg(array('pp_action' => 'executepay'), home_url()));
         $redirectUrls->setCancelUrl($this->cancel_url);
         $payer = new Payer();
         $payer->setPaymentMethod("paypal");
         $details = new Details();
         if (isset($PaymentData['shippingamt'])) {
             $details->setShipping($PaymentData['shippingamt']);
         }
         if (isset($PaymentData['taxamt'])) {
             $details->setTax($PaymentData['taxamt']);
         }
         $details->setSubtotal($PaymentData['itemamt']);
         $amount = new Amount();
         $amount->setCurrency(PP_CURRENCY);
         $amount->setTotal(WC()->cart->total);
         $amount->setDetails($details);
         $items = new ItemList();
         $items->setItems($OrderItems);
         $transaction = new Transaction();
         $transaction->setAmount($amount);
         $transaction->setDescription('');
         $transaction->setItemList($items);
         //$transaction->setInvoiceNumber($this->invoice_prefix.$order_id);
         $payment = new Payment();
         $payment->setRedirectUrls($redirectUrls);
         $payment->setIntent("sale");
         $payment->setPayer($payer);
         $payment->setTransactions(array($transaction));
         $payment->create($this->getAuth());
         $this->add_log(print_r($payment, true));
         //if payment method was PayPal, we need to redirect user to PayPal approval URL
         if ($payment->state == "created" && $payment->payer->payment_method == "paypal") {
             WC()->session->paymentId = $payment->id;
             //set payment id for later use, we need this to execute payment
             return $payment->links[1]->href;
         }
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         wc_add_notice(__("Error processing checkout. Please try again. ", 'woocommerce'), 'error');
         $this->add_log($ex->getData());
     } catch (Exception $ex) {
         wc_add_notice(__('Error processing checkout. Please try again. ', 'woocommerce'), 'error');
         $this->add_log($ex->getMessage());
     }
 }
예제 #28
0
 public function doSaleAPI($creditCardId, $total)
 {
     $apiContext = new ApiContext(new OAuthTokenCredential(self::CLIENT_ID, self::SECRET));
     //            $card = new CreditCard();
     //            $card->setType($payment_type);
     //            $card->setNumber($card_number);
     //            $card->setExpire_month($exp_month);
     //            $card->setExpire_year($exp_year);
     //	    $card->setCvv2($csc);
     //            $card->setFirst_name($first_name);
     //            $card->setLast_name($last_name);
     $creditCardToken = new CreditCardToken();
     $creditCardToken->setCreditCardId($creditCardId);
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCardToken($creditCardToken);
     $payer = new Payer();
     $payer->setPayment_method("credit_card");
     $payer->setFunding_instruments(array($fundingInstrument));
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription("creating a direct payment with credit card");
     $payment = new Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     try {
         $payment->create($apiContext);
         //$card->create($apiContext);
     } catch (\PPConnectionException $ex) {
         echo "Exception:" . $ex->getMessage() . PHP_EOL;
         var_dump($ex->getData());
         exit(1);
     }
     return $payment->getId();
 }
예제 #29
0
 /**
  * [makePaymentUsingPayPal description]
  * @param  [type] $order     [description]
  * @param  [type] $currency  [description]
  * @param  [type] $returnUrl [description]
  * @param  [type] $cancelUrl [description]
  * @return [type]            [description]
  */
 function makePaymentUsingPayPal($order, $currency, $returnUrl, $cancelUrl)
 {
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     //  $payee = new Payee();
     //  $payee->setEmail((string)$order['email_paypal']);
     // Specify the payment amount.
     $item = new Item();
     $item->setQuantity((string) $order['quantity']);
     $item->setName($order['description']);
     $item->setPrice((string) $order['input_price']);
     $item->setCurrency($currency);
     $item->setSku($order['item_number']);
     $array_item[] = $item;
     if (isset($order['price_ship'])) {
         $item_ship = new Item();
         $item_ship->setQuantity('1');
         $item_ship->setName('shipping');
         $item_ship->setPrice((string) $order['price_ship']);
         $item_ship->setCurrency($currency);
         $item_ship->setSku('shipping');
         $array_item[] = $item_ship;
     }
     $item_list = new ItemList();
     $item_list->setItems($array_item);
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal((string) $order['total']);
     //$amount->setTax()
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($order['description']);
     $transaction->setItemList($item_list);
     // $transaction->setPayee($payee);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($returnUrl);
     $redirectUrls->setCancelUrl($cancelUrl);
     $payment = new Payment();
     $payment->setRedirectUrls($redirectUrls);
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create($this->getApiContext());
     return $payment;
 }
예제 #30
0
 /**
  * @group integration
  */
 public function testReauthorize()
 {
     $authorization = Authorization::get('7GH53639GA425732B');
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $authorization->setAmount($amount);
     try {
         $authorization->reauthorize();
     } catch (PayPalConnectionException $ex) {
         //var_dump($ex->getMessage());
         $this->assertEquals(strpos($ex->getMessage(), "500"), false);
     }
     $authorization->setId(null);
     try {
         $authorization->reauthorize();
     } catch (\InvalidArgumentException $ex) {
         $this->assertEquals($ex->getMessage(), "Id cannot be null");
     }
 }