x***@163.com
x***@163.com
  • 发布:2023-02-11 12:40
  • 更新:2023-02-11 12:40
  • 阅读:1001

全新个人发卡网源码开源版内置免签支付接口可对接易支付

分类:流应用

  在本文中,让我们看看如何实施支付网关PHP源代码项目。我们已经在一篇用PHP语言集成的文章中清楚地解释了这个过程。但是所有技术的步骤都是相同的。因此,请阅读此处的集成指南。其实步骤很简单,我们只需要输入商户密钥和salt。
  
  源码:paywks.top/ka
  
  这里我有使用框架,因为支付网关不像简单的过程。我们需要手动设置一些更改并实施代码。所以当我们使用COREPHP时,会面临更多的错误处理困难。这就是为什么大多数开发人员建议使用Laravel、Codeigniter等框架的原因。
  
  支付网关PHP要遵循的步骤
  
  如果您是该类别的初学者,请阅读官方文档。之后,您对构建代码有了一些想法。第一步是选择最好的支付网关提供商之一。
  
  我希望你的系统上已经有下载节点,以提取依赖管理器。所以首先通过命令提示符创建Laravel项目。
  
  useShipu\Aamarpay\Aamarpay;
  $config=[
  'store_id'=>'Yourstoreid',
  'signature_key'=>'Yoursignaturekey',
  'sandbox'=>true,
  'redirect_url'=>[
  'success'=>[
  'route'=>'payment.success'
  ],
  'cancel'=>[
  'route'=>'payment.cancel'
  ]
  ]
  ];
  $payment=newAamarpay($config);
  
  上面的代码解释了连接到数据库的模块的必填字段。然后只有我们能够与数据库系统进行通信。否则,确切的数据不会在后端通信中传输。
  
  
  use\Shipu\Aamarpay\Aamarpay;
  ...
  $payment=newAamarpay(config('aamarpay'));
  return$payment->customer([
  'cus_name'=>'ShipuAhamed',//Customername
  'cus_phone'=>'01616022669'//CustomerPhone
  'cus_email'=>'shipuahamed01@gmail.com',//Customeremail
  ])->transactionId()->amount(3500)->hiddenValue();
  or
  return$payment->customer([
  'cus_name'=>'ShipuAhamed',//Customername
  'cus_phone'=>'9854345483'//CustomerPhone
  'cus_email'=>'shipuahamed01@gmail.com',//Customeremail
  ])->amount(3500)->hiddenValue();
  
  Route::post('payment/success','YourMakePaymentsController@paymentSuccess')->name('payment.success');
  Route::post('payment/failed','YourMakePaymentsController@paymentFailed')->name('payment.failed');
  Route::post('payment/cancel','YourMakePaymentsController@paymentCancel')->name('payment.cancel');
  PHP库
  
  接下来,您需要在数据库中创建一个表来保存交易明细。接下来是在MySQL数据库中创建订单表的SQL。
  
  CREATETABLEorders(
  idint(11)NOTNULLAUTO_INCREMENT,
  namevarchar(100)COLLATEutf8_unicode_ciNOTNULL,
  emailvarchar(255)COLLATEutf8_unicode_ciNOTNULL,
  card_numbigint(20)NOTNULL,
  card_cvcint(5)NOTNULL,
  card_exp_monthvarchar(2)COLLATEutf8_unicode_ciNOTNULL,
  card_exp_yearvarchar(5)COLLATEutf8_unicode_ciNOTNULL,
  item_namevarchar(255)COLLATEutf8_unicode_ciNOTNULL,
  item_numbervarchar(50)COLLATEutf8_unicode_ciNOTNULL,
  item_pricefloat(10,2)NOTNULL,
  item_price_currencyvarchar(10)COLLATEutf8_unicode_ciNOTNULLDEFAULT'usd',
  paid_amountvarchar(10)COLLATEutf8_unicode_ciNOTNULL,
  paid_amount_currencyvarchar(10)COLLATEutf8_unicode_ciNOTNULL,
  txn_idvarchar(100)COLLATEutf8_unicode_ciNOTNULL,
  payment_statusvarchar(50)COLLATEutf8_unicode_ciNOTNULL,
  createddatetimeNOTNULL,
  modifieddatetimeNOTNULL,
  PRIMARYKEY(id)
  )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_unicode_ci;
  
  数据库配置(dbConfig.php)
  
  您将需要dbConfig.php文件来连接和选择数据库。在数据库凭证后指定数据库主机($dbHost)、用户名($dbUsername)、密码($dbPassword)和名称($dbName)。
  接下来,我们将使用StripePHP库来处理卡支付。该图书馆可在此处获得。
  
  //checkwhetherstripetokenisnotempty
  if(!empty($_POST['stripeToken'])){
  //gettoken,cardanduserinfofromtheform
  $token=$_POST['stripeToken'];
  $name=$_POST['name'];
  $email=$_POST['email'];
  $card_num=$_POST['card_num'];
  $card_cvc=$_POST['cvc'];
  $card_exp_month=$_POST['exp_month'];
  $card_exp_year=$_POST['exp_year'];
  //includeStripePHPlibrary
  require_once('stripe-php/init.php');
  //setapikey
  $stripe=array(
  "secret_key"=>"Your_API_Secret_Key",
  "publishable_key"=>"Your_API_Publishable_Key"
  );
  \Stripe\Stripe::setApiKey($stripe['secret_key']);
  //addcustomertostripe
  $customer=\Stripe\Customer::create(array(
  'email'=>$email,
  'source'=>$token
  ));
  //iteminformation
  $itemName="PremiumScriptCodexWorld";
  $itemNumber="PS123456";
  $itemPrice=55;
  $currency="usd";
  $orderID="SKA92712382139";
  //chargeacreditoradebitcard
  $charge=\Stripe\Charge::create(array(
  'customer'=>$customer->id,
  'amount'=>$itemPrice,
  'currency'=>$currency,
  'description'=>$itemName,
  'metadata'=>array(
  'order_id'=>$orderID
  )
  ));
  //retrievechargedetails
  $chargeJson=$charge->jsonSerialize();
  //checkwhetherthechargeissuccessful
  if($chargeJson['amount_refunded']==0&&empty($chargeJson
  ['failure_code'])&&$chargeJson['paid']==1&&$chargeJson['captured']==1){
  //orderdetails
  $amount=$chargeJson['amount'];
  $balance_transaction=$chargeJson['balance_transaction'];
  $currency=$chargeJson['currency'];
  $status=$chargeJson['status'];
  $date=date("Y-m-dH:i:s");
  //includedatabaseconfigfile
  include_once'dbConfig.php';
  //inserttansactiondataintothedatabase
  $sql=
  "INSERTINTOorders(name,email,card_num,card_cvc,card_exp_month,card_exp_year,
  item_name,item_number,item_price,item_price_currency,paid_amount,
  paid_amount_currency,txn_id,payment_status,created,modified)VALUES
  ('".$name."','".$email."','".$card_num."','".$card_cvc."','".$card_exp_month."',
  '".$card_exp_year."','".$itemName."','".$itemNumber."','".$itemPrice."','".$currency."',
  '".$amount."','".$currency."','".$balance_transaction."'
  ,'".$status."','".$date."','".$date."')";
  $insert=$db->query($sql);
  $last_insert_id=$db->insert_id;
  //iforderinsertedsuccessfully
  if($last_insert_id&&$status=='succeeded'){
  $statusMsg="<h2>Thetransactionwassuccessful.</h2>
  <h4>OrderID:{$last_insert_id}</h4>";
  }else{
  $statusMsg="Transactionhasbeenfailed";
  }
  }else{
  $statusMsg="Transactionhasbeenfailed";
  }
  }else{
  $statusMsg="Formsubmissionerror.......";
  }
  //showsuccessorerrormessage
  echo$statusMsg;

0 关注 分享

要回复文章请先登录注册