如何解决如果价值/价格低于或等于20,如何消除一种付款方式
我有这个用于MercadoPago付款网关的库,并且我试图消除价值/价格低于或等于20的付款类型ID“票”形式的付款选项。
以下是官方文档(巴西)https://www.mercadopago.com.ar/developers/en/guides/resources/localization/payment-methods/
$preference->payment_methods = array(
"excluded_payment_types" => array(
array("id" => "digital_wallet")
),"installments" => 12
);
完整代码:
<?PHP defined('BASEPATH') OR exit('No direct script access allowed');
require_once 'mercadopago/autoload.PHP';
class mercadopagoapi{
public function __construct($mercadopago_access_token = null) {
MercadoPago\SDK::setAccesstoken($mercadopago_access_token);
}
public function create_payment($data = array()){
try {
$amount = $data['currency_code'];
// Create a preference object
$preference = new \MercadoPago\Preference();
// Create an item in the preference
$item = new \MercadoPago\Item();
$item->title = $data['description'];
$item->quantity = 1;
$item->unit_price = $data['amount'];
$preference->items = array($item);
$orderID = $data['order_id'];
$backUrl = $data['backUrl'].'?paymentOption=mercadopago&order_id='.$orderID .'&amount=$amount';
$backUrlFailure = 'https:/example.com/';
// Block PayPal
$preference->payment_methods = array(
"excluded_payment_types" => array(
array("id" => "digital_wallet")
),"installments" => 12
);
// Back Urls
$preference->back_urls = array(
"success" => $backUrl,"failure" => $backUrlFailure,"pending" => $backUrl
);
$ipnUrl = $data['ipnUrl'].'?paymentOption=mercadopago-ipn';
$preference->notification_url = $ipnUrl;
$preference->auto_return = "approved";
$preference->save();
// Create a customer object
$payer = new \MercadoPago\Payer();
// Create payer information
$payer->name = $data['email'];
$payer->email = $data['email'];
$payer->address = array(
"street_name" => 'Av. Brig. Faria Lima'
);
// Check if test mode true or false
// and set redirect url as per
if ($data['mode'] == 'TEST') {
$redirectUrl = $preference->sandBox_init_point;
} else {
$redirectUrl = $preference->init_point;
}
return (object)[
'status' => 'success','id' => $preference->id,'redirect_url' => $redirectUrl
];
} catch (Exception $e) {
return [
'status' => 'error','message' => $e->getMessage()
];
}
}
/**
*
* @param string $ordderData - Order ID
* @param string -$stripetoken - Stripe Token
*
* request to Stripe checkout
*---------------------------------------------------------------- */
public function prepareIpnRequestData($requestData)
{
$merchant_order = null;
switch($requestData["topic"]) {
case "payment":
$payment = \MercadoPago\Payment::find_by_id($requestData["id"]);
// Get the payment and the corresponding merchant_order reported by the IPN.
$merchant_order = \MercadoPago\MerchantOrder::find_by_id($payment->order->id);
break;
case "merchant_order":
$merchant_order = \MercadoPago\MerchantOrder::find_by_id($requestData["id"]);
break;
}
$paid_amount = 0;
foreach ($merchant_order->payments as $payment) {
if ($payment['status'] == 'approved'){
$paid_amount += $payment['transaction_amount'];
}
}
$status = $message = '';
// If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items
if($paid_amount >= $merchant_order->total_amount){
if (count($merchant_order->shipments)>0) { // The merchant_order has shipments
if($merchant_order->shipments[0]->status == "ready_to_ship") {
$status = 'total_paid';
$message = "Totally paid. Print the label and release your item.";
}
} else { // The merchant_order don't has any shipments
$status = 'total_paid';
$message = "Totally paid. Release your item.";
}
} else {
$status = 'not_paid';
$message = "Not paid yet. Do not release your item.";
}
header("HTTP/1.1 200 OK");
return [
'status' => $status,'message' => $message,'raw_data' => $merchant_order
];
}
public function get_id_details($data_payment = "") {
$merchant_order = null;
$merchant_order = \MercadoPago\MerchantOrder::find_by_id($data_payment->merchant_order_id);
if (!isset($merchant_order)) {
$result = [
'status' => 'canceled',];
}
foreach ($merchant_order->payments as $payment) {
if ($payment->id == $data_payment->collection_id) {
if ($payment->status == "approved") {
$result = [
'status' => 'completed','data' => $payment
];
}else{
$result = [
'status' => 'canceled','data' => $payment
];
}
}else{
$result = [
'status' => 'canceled',];
}
}
return (object)$result;
}
}
在付款网关页面上具有所有付款选项的图像,带有红色标记的图像是我要在价值/价格低于或等于20时取消的图像。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。