用PHP条带化支付 [英] Stripe payment with php

查看:89
本文介绍了用PHP条带化支付的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,该网站的前端由angularjs制作,后端由laravel制作.我想整合条纹支付.我面临向laravel添加angularjs api进行条纹支付的困难.因此,我正在尝试仅使用过程性php来解决该问题.这是我的代码.

I am developing a website that is front end made with angularjs and backend with laravel. I want to integrate stripe payment. I am facing difficulty to add a angularjs api to laravel for stripe payment. So, I am trying to solve it with only procedural php. here is my code.

<?php
require_once('/stripe-php/lib/Stripe.php');
require_once('/stripe-php/lib/Charge.php');

Stripe::setApiKey('my-secret-key');
$charge = Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => $token ));
if ($charge) {
  echo "Payment successcul";
}
else {
  echo "Not success";
}

?>

我可以得到令牌.但是付款没有处理,我看到空白页.

I can get the token. But the payment is not processing and I see a blank page.

推荐答案

请按照以下步骤进行分期付款.1.从 https://stripe.com/docs/libraries#php 下载条纹文件夹2.将文件夹包括在项目的www文件夹中.3.制作一个新的PHP文件,并将此代码放入文件中.

Follow this step to stripe payment. 1. download stripe folder from https://stripe.com/docs/libraries#php 2. Include the folder in your www folder in your project. 3. Make new PHP file and put this code into file.

<?php
{
  require_once "./Stripe-php/init.php"; //include your stripe folder
  function __construct()
  {
      // put your keys here
      \Stripe\Stripe::setApiKey("Secret-Key");
  }

 //put your code into function.

  $token = $_POST['stripeToken']; // Token ID

  $charge = \Stripe\Charge::create([
       'amount' => $20 * 100,
       'currency' => 'usd',
       'description' => 'Message',
       'source' => $token,
   ]);

    if($charge['status'] == "succeeded"){  // if success
        $status=1;
        $post['charge_id']=$charge['id'];
        $post['amount']=$charge['amount'];
        $post['funding']=$charge['source']['funding'];
        $post['holder_name']=$charge['source']['name'];
        $post['brand']=$charge['source']['brand'];
        $Message="Payment Success";
    }
    else{
        $status=2;                        // failed
        $post=null;
        $Message="Payment Failed";
    }

    $data["status"] = ($status > 1) ? FAILED : SUCCESS;
    $data["message"]=$Message;
    $data["PaymentData"]=$post;
    return $data; // JSON Returen
}
?>

这篇关于用PHP条带化支付的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆