gpt4 book ai didi

php - 在哪里可以找到结算协议(protocol) ID 然后在结帐时使用它

转载 作者:太空宇宙 更新时间:2023-11-03 15:58:19 26 4
gpt4 key购买 nike

大家好,我对在用户批准计费计划后在哪里可以找到计费协议(protocol) ID (BAID) 感到困惑。

使用 REST-API

目前paypal在我执行协议(protocol)后返回这个。

Agreement {#346 ▼
-_propMap: array:9 [▼
"id" => "I-N61SE6562BGN"
"state" => "Active"
"description" => "This is a subscription fee for using Talent Scout. It will be use to maintain the site and make users secure."
"payer" => Payer {#349 ▶}
"plan" => Plan {#350 ▶}
"links" => array:5 [▶]
"start_date" => "2019-06-17T07:00:00Z"
"shipping_address" => Address {#364 ▶}
"agreement_details" => AgreementDetails {#365 ▶}
]
}

我很困惑上面代码中的ID是不是BAID。如果它是我正在寻找的 BAID,那么我想将其插入结帐中,这样用户以后结帐时就不必再次登录。

用户选择和结帐时的代码

$payer = new Payer();
$payer->setPaymentMethod('paypal');
$total = 0;
Session::set('duration', $request['duration']);
if($request['duration'] == '1'){
$item_1 = new Item();
$item_1->setName('1 week duration') // item name
->setCurrency('PHP')
->setQuantity(1)
->setPrice($request['hiddenprice'][0]); // unit price
$total = $request['hiddenprice'][0];
}
elseif($request['duration'] == '2'){
$item_1 = new Item();
$item_1->setName('2 weeks duration') // item name
->setCurrency('PHP')
->setQuantity(1)
->setPrice($request['hiddenprice'][1]); // unit price
$total = $request['hiddenprice'][1];
}
elseif ($request['duration'] == '3') {
$item_1 = new Item();
$item_1->setName('3 weeks duration') // item name
->setCurrency('PHP')
->setQuantity(1)
->setPrice($request['hiddenprice'][2]); // unit price
$total = $request['hiddenprice'][2];
}

// add item to list
$item_list = new ItemList();
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('PHP')
->setTotal($total);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(\URL::route('payment.status'))
->setCancelUrl(\URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (\Config::get('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
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
Session::put('paypal_payment_id', $payment->getId());
if(isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
Session::flash('failed', 'Something went wrong!');
return Redirect::to('/home')
->with('error', 'Unknown error occurred');
}

支付成功代码

// Get the payment ID before session clear
$payment_id = Session::get('paypal_payment_id');
// clear the session payment ID
Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
Session::flash('failed', 'Something went wrong!');
return Redirect::to('/paymentprocess')
->with('error', 'Payment failed');
}
$payment = Payment::get($payment_id, $this->_api_context);
// 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(Input::get('PayerID'));

//Execute the payment
$result = $payment->execute($execution, $this->_api_context);
// echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
// dd($result->id);
if ($result->getState() == 'approved') { // payment made
$data = new Paypalpayment;
$user = User::find(Session::get('id'));
$data->id = null;
$data->payment_id = $result->id;
$data->user_id = Session::get('id');
$data->firstname = $user['firstname'];
$data->lastname = $user['lastname'];
$data->state = 'pending';
$data->duration = Session::get('duration');
$data->save();
Session::forget('duration');
Session::flash('success', 'Payment Successful!');
return Redirect::to('/paymentprocess')
->with('success', 'Payment success');
}
Session::flash('failed', 'Payment failed!!');
return Redirect::to('/paymentprocess')
->with('error', 'Payment failed');

最佳答案

是的,执行协议(protocol)后返回对象中的ID就是计费协议(protocol)ID,以后可以用它来查询协议(protocol)的信息。

这是另一个可能有帮助的例子:https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/billing/ExecuteAgreement.php

关于php - 在哪里可以找到结算协议(protocol) ID 然后在结帐时使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42250216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com