本文整理汇总了PHP中PayPal\Api\Payment::setTransactions方法的典型用法代码示例。如果您正苦于以下问题:PHP Payment::setTransactions方法的具体用法?PHP Payment::setTransactions怎么用?PHP Payment::setTransactions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PayPal\Api\Payment
的用法示例。
在下文中一共展示了Payment::setTransactions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* @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());
}
示例2: makePaymentUsingPayPal
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;
}
示例3: createPayment
/**
* Creates a PayPal payment
*
* @param array $configuration
* @param Payer $payer
* @param RedirectUrls $redirectUrls
* @param Transaction $transaction
*
* @return Payment
*/
public function createPayment(array $configuration, Payer $payer, RedirectUrls $redirectUrls, Transaction $transaction) : Payment
{
$apiContext = $this->getApiContext($configuration);
$payment = new Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions([$transaction]);
return $payment->create($apiContext);
}
示例4: payment
/**
* @throws \InvalidArgumentException
*
* @return Payment
*/
private function payment() : Payment
{
if ($this->payment === null) {
$this->payment = app(Payment::class);
$this->payment->setIntent('sale');
$this->payment->setPayer($this->payer());
$this->payment->setRedirectUrls($this->redirectUrls());
$this->payment->setTransactions([$this->transaction()]);
$this->payment->create($this->apiContext);
}
return $this->payment;
}
示例5: paypal
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;
}
}
}
示例6: getPayment
/**
* @see http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html
*
* @return Payment
*/
public function getPayment()
{
$payer = $this->getPayer();
if (!$payer || !$payer instanceof Payer) {
throw new InvalidArgumentException("Method getPayer has to return instance of Payer. Instead " . gettype($payer) . " given.");
}
if (!$payer->getPaymentMethod()) {
$payer->setPaymentMethod('paypal');
}
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer);
$transactions = $this->getTransactions();
$this->checkTransactions($transactions);
$payment->setTransactions($transactions);
return $payment;
}
示例7: createNewPayment
public static function createNewPayment()
{
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
}
示例8: processPayment
/**
* {@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;
}
示例9: authorize
public static function authorize()
{
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpireMonth("11");
$card->setExpireYear("2019");
$card->setCvv2("012");
$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));
$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();
$resArray = $paymnt->toArray();
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
示例10: process
public function process($orderData, $cartProducts = [])
{
$this->setApiContext();
$this->_apiContext->setConfig(['mode' => Configuration::getConfiguration('paypal_payment_mode'), 'service.EndPoint' => Configuration::getConfiguration('paypal_payment_url'), 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => Configuration::getConfiguration('paypal_payment_log'), 'log.FileName' => storage_path('logs/paypal.log'), 'log.LogLevel' => 'FINE']);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$itemList = new ItemList();
$subTotal = 0;
$taxTotal = 0;
foreach ($cartProducts as $product) {
$item = new Item();
$model = $product['model'];
$item->setName($model->title)->setCurrency('USD')->setQuantity($product['qty'])->setSku($model->sku)->setPrice($product['price']);
$itemList->addItem($item);
$subTotal += $product['price'] * $product['qty'];
$taxTotal += $product['tax_amount'] * $product['qty'];
}
$total = $subTotal + $taxTotal;
$shippingOption = $orderData['shipping_method'];
$shipping = Shipping::get($shippingOption);
$details = new Details();
$details->setShipping($shipping->getAmount())->setTax($taxTotal)->setSubtotal($subTotal);
$amount = new Amount();
$amount->setCurrency('USD')->setTotal($total)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment description')->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(route('paypal.store'));
$redirectUrls->setCancelUrl(route('paypal.cancel'));
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions([$transaction]);
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return $redirectUrl;
}
示例11: callCreate
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;
}
示例12: store
public function store(Request $request)
{
//stores a new order for confirmation
$result = false;
$msg = "";
$info = $request->all();
//return dd($request->all());
//return var_dump( $info );
if (Auth::check()) {
if (User::profileComplete(Auth::user())) {
$paypal_conf = config('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
$fabric = Fabric::find($info["fabric"]);
$user = Auth::user();
$order = new Order();
if ($fabric->stock >= $info["totalAmount"] && $info["totalAmount"] > 0) {
//create new order with from the given data.
$order->user_id = $user->id;
$order->fabric_id = $fabric->id;
$order->fabric_name = $fabric->name;
$order->amount = $info["totalAmount"];
$weight = $info["totalAmount"] / 5 * (2.5 * 1.2);
$order->shipping = $weight;
$order->type_sample = $info["type-sample"];
$order->carrier = $info["carrier"];
$order->sub_total = $fabric->priceYard * $info["totalAmount"];
$order->total = $order->sub_total + $order->shipping;
$order->status = "not-confirmed";
$fabric->stock -= $order->amount;
$result = true;
$dataMail["subTotal"] = $order->sub_total;
$dataMail["shipping"] = $order->shipping;
$dataMail["carrier"] = $order->carrier;
$dataMail["type-sample"] = $order->type_sample;
$dataMail["total"] = $order->total;
$dataMail["fabric-name"] = $fabric->name;
$dataMail["name"] = $user->name;
$dataMail["city"] = $user->city;
$dataMail["country"] = $user->country;
$dataMail["zp"] = $user->zp_code;
$dataMail["address"] = $user->address;
$dataMail["email"] = $user->email;
$dataMail["totalAmount"] = $order->amount;
// paypal logic starts here
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($order->fabric_name . $order->created_at);
$item->setCurrency('USD');
$item->setQuantity($order->amount);
$item->setPrice($fabric->priceYard);
$itemCarrier = new Item();
$itemCarrier->setName("Shipping Price");
$itemCarrier->setCurrency('USD');
$itemCarrier->setQuantity(1);
$itemCarrier->setPrice($weight);
// add item to list
$item_list = new ItemList();
$item_list->setItems([$itemCarrier, $item]);
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal($order->sub_total + $weight);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setItemList($item_list);
$transaction->setDescription('New Fabric Order');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(url('successPay/orders'));
$redirect_urls->setCancelUrl(url("cancelPay/orders"));
$payment = new Payment();
$payment->setIntent('Sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirect_urls);
$payment->setTransactions(array($transaction));
try {
PPHttpConfig::$DEFAULT_CURL_OPTS[CURLOPT_SSLVERSION] = 4;
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (config('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
echo '<pre>';
print_r(json_decode($pce->getData()));
exit;
exit;
} else {
die('Some error occur, sorry for inconvenient');
}
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
$paypal_data = ['paypal_payment_id' => $payment->getId(), "fabric" => $fabric, "order" => $order, "data_mail" => $dataMail, "paypal_context" => $this->_api_context];
Session::put("paypal_data", $paypal_data);
$order_data = ["msg" => "Error: could not connect to paypal", "result" => false];
//.........这里部分代码省略.........
示例13: createPayment
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;
}
}
示例14: substr
/**
* @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;
}
示例15: payThroughPayPal
/**
* Создаем платеж типа paypal
* в случае успеха возвращает массив с ид-платежа,
* токеном и редирект-урлом куда нужно направить пользователя для оплаты
*
* @param double $pay_sum
* @param string $paymentInfo
* @param string $sku - internal UNIT ID
*
* @return array | null
*/
public function payThroughPayPal($pay_sum, $paymentInfo, $sku = null)
{
set_time_limit(120);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal($pay_sum);
$item1 = new Item();
$item1->setName($paymentInfo)->setCurrency('USD')->setQuantity(1)->setPrice($pay_sum);
// Ид товара/услуги на вашей стороне
if ($sku) {
$item1->setSku($sku);
}
$itemList = new ItemList();
$itemList->setItems([$item1]);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('Payment to DirectLink');
$transaction->setItemList($itemList);
$transaction->setNotifyUrl($this->config['url.notify_url']);
//**
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl($this->config['url.return_url']);
$redirect_urls->setCancelUrl($this->config['url.cancel_url']);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions([$transaction]);
$payment->setRedirectUrls($redirect_urls);
//$payment->setId('123456789'); //**
$payment->create($this->_apiContext);
//var_dump($payment); exit;
$links = $payment->getLinks();
foreach ($links as $link) {
if ($link->getMethod() == 'REDIRECT') {
$redirect_to = $link->getHref();
$token = time() . "_" . rand(100, 999);
$tmp = parse_url($redirect_to);
if (isset($tmp['query'])) {
parse_str($tmp['query'], $out);
if (isset($out['token'])) {
$token = $out['token'];
}
}
$paymentId = $payment->getId();
// ++ DEBUG LOG
$this->logging_queryes('paymentCreate_' . $paymentId . '.txt', $payment->toJSON());
// -- DEBUG LOG
return ['paymentId' => $paymentId, 'token' => $token, 'redirect_to' => $redirect_to];
}
}
return null;
}