首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实施Payum/Laravel定期付款

实施Payum/Laravel定期付款
EN

Stack Overflow用户
提问于 2014-10-15 18:58:44
回答 3查看 5.3K关注 0票数 17

我遇到了一些问题,我已经成功地实现了结帐快车(或似乎是),但我的系统也需要订阅选项,遵循这个示例

现在,我的问题是,在Laravel中,您不能简单地放置一些随机文件,所以我试图以正确的方式进行,遗憾的是,没有关于类和方法的文档,包括库中的类和方法。

我已经在控制器中创建了一些函数(我不知道这是否是正确的方法),我现在面临的问题是尝试createRecurringPayment()应用所需的定期支付金额,这是我想的最后一步。

谢谢你帮忙。

  • app/controllers/PaypalController.php 公共函数$this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');prepareExpressCheckout(){ $storage =$ $storage->createModel();$details‘’PAYMENTREQUEST_CURRENCYCODE‘=’美元‘;$details’‘PAYMENTREQUEST_AMT’= 1.23;$ $storage->updateModel($details);$captureToken = $this->getTokenFactory()->createCaptureToken('paypal_es',$details,‘payment_done’;$details‘’RETURNURL‘= $captureToken->getTargetUrl();$details’‘CANCELURL’=$captureToken-->getTargetUrl();$ $details ->updateModel($details);返回\重定向:to($captureToken->getTargetUrl());}公共函数prepareSubscribe(){ $storage =$$storage=$ $storage->createModel();$details‘’PAYMENTREQUEST__AMT‘= 0;$details'L_BILLINGTYPE0’= Api::BILLINGTYPE_RECURRING_PAYMENTS;$details'L_BILLINGAGREEMENTDESCRIPTION0‘=“suscripón por X meses";$details’‘NOSHIPPING’= 1;$ $captureToken ->updateModel($details);$captureToken=$captureToken $details,‘payment_done’;$storage->updateModel($details);返回\Redirect::to($captureToken->getTargetUrl();}公共函数createRecurringPayment(){ $payum_token = Input::get('payum_token');$request = \App::make('request');$token-token>属性集(‘payum_token’,$payum_token);$this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');= ($request);//$$request->失效( $token );$agreementStatus =新GetHumanStatus($token);$payment->execute($agreementStatus);if (!$agreementStatus>isSuccess()){标头(‘HTTP/1.1 400坏请求’,真,400);退出;} $agreementDetails =$agreementStatus>getModel();$storage =$存储->createModel();$递归付费‘’TOKEN‘=$agreementDetails’‘TOKEN’;$递归支付‘DESC=’订阅天气预报一周。每日0.05美元;递归agreementDetails‘’EMAIL‘=$388 day’‘EMAIL’;$递归agreementDetails‘’AMT‘= 0.05;$递归agreementDetails’‘CURRENCYCODE’=‘美元’;$递归agreementDetails‘’BILLINGFREQUENCY‘= 7;$递归agreementDetails’‘PROFILESTARTDATE’= date(DATE_ATOM);$递归agreementDetails‘’BILLINGPERIOD‘= Api::BILLINGPERIOD_DAY;$payment->execute(新的$recurringPaymentDetails);$doneToken = $this->createToken('paypal_es',$recurringPaymentDetails,'payment_done');返回\重定向::to($doneToken>getTargetUrl();}
  • app/Broades.php 路由:get(‘/payment’,array('as‘=>’支付‘,’使用‘=>’PaymentController@payment‘’);路由:get(‘/PaymentController/done’),数组(‘as’=>‘PaymentController@es’);‘=>’PaymentController@es‘);’=> 'paypal_es_prepare‘’,'uses‘=>’PaypalController@prepareExpressCheckout‘);Route::get('/payment/paypal/subscribe/prepare',数组(‘as’as‘paypal_re_create’,‘使用’=>‘PaypalController@prepareSubscribe’);Route::get('/payment/paypal/subscribe/create',数组(‘as’as‘=> 'payment_create',’=>‘PaypalController@createRecurringPayment’);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-02-13 10:18:06

我发现了这个问题。它是与参数,我们传递给创建循环支付功能。以下是协议和支付创建的功能。它应该能正常工作。

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use Payum\Core\Request\GetHumanStatus;
use Payum\LaravelPackage\Controller\PayumController;
use Payum\Paypal\ExpressCheckout\Nvp\Api;
use Payum\Core\Request\Sync;
use Payum\Paypal\ExpressCheckout\Nvp\Request\Api\CreateRecurringPaymentProfile;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PayPalController extends PayumController {

    public function prepareSubscribeAgreement() {

        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $details = $storage->create();
        $details['PAYMENTREQUEST_0_AMT'] = 0;
        $details['L_BILLINGTYPE0'] = Api::BILLINGTYPE_RECURRING_PAYMENTS;
        $details['L_BILLINGAGREEMENTDESCRIPTION0'] = "Weather subscription";
        //$details['NOSHIPPING'] = 1;
        $storage->update($details);

        $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $details, 'paypal_subscribe');

        return \Redirect::to($captureToken->getTargetUrl());
    }

    public function createSubscribePayment(Request $request) {
        $request->attributes->set('payum_token', $request->input('payum_token'));

        $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
        $gateway = $this->getPayum()->getGateway($token->getGatewayName());

        $agreementStatus = new GetHumanStatus($token);
        $gateway->execute($agreementStatus);

        if (!$agreementStatus->isCaptured()) {
            header('HTTP/1.1 400 Bad Request', true, 400);
            exit;
        }

        $agreement = $agreementStatus->getModel();

        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $recurringPayment = $storage->create();
        $recurringPayment['TOKEN'] = $agreement['TOKEN'];
        $recurringPayment['PAYERID'] = $agreement['PAYERID'];
        $recurringPayment['PROFILESTARTDATE'] = date(DATE_ATOM);
        $recurringPayment['DESC'] = $agreement['L_BILLINGAGREEMENTDESCRIPTION0'];
        $recurringPayment['BILLINGPERIOD'] = Api::BILLINGPERIOD_DAY;
        $recurringPayment['BILLINGFREQUENCY'] = 7;
        $recurringPayment['AMT'] = 0.05;
        $recurringPayment['CURRENCYCODE'] = 'USD';
        $recurringPayment['COUNTRYCODE'] = 'US';
        $recurringPayment['MAXFAILEDPAYMENTS'] = 3;

        $gateway->execute(new CreateRecurringPaymentProfile($recurringPayment));
        $gateway->execute(new Sync($recurringPayment));

        $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $recurringPayment, 'payment_done');

        return \Redirect::to($captureToken->getTargetUrl());
    }

    public function done(Request $request) {
        /** @var Request $request */
        //$request = \App::make('request');
        $request->attributes->set('payum_token', $request->input('payum_token'));

        $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
        $gateway = $this->getPayum()->getGateway($token->getGatewayName());

        $gateway->execute($status = new GetHumanStatus($token));

        return \Response::json(array(
                    'status' => $status->getValue(),
                    'details' => iterator_to_array($status->getFirstModel())
        ));
    }

}

路线:

代码语言:javascript
复制
Route::get('paypal/agreement', 'PayPalController@prepareSubscribeAgreement');
    Route::get('paypal/subscribe', [
        'as' => 'paypal_subscribe',
        'uses' => 'PayPalController@createSubscribePayment'
    ]);
    Route::get('paydone', [
        'as' => 'payment_done',
        'uses' => 'PayPalController@done'
    ]);

只需打开www.example.com/ PayPal /agreement,您就可以访问PayPal。

票数 3
EN

Stack Overflow用户

发布于 2015-07-13 06:42:13

在我的项目中,我使用了以下库,它对我帮助很大:

https://github.com/amirduran/duranius-paypal-rest-api-php-library

以下是一些特性:

  • 安装简单--只有一个文件
  • 库被实现为PHP类。
  • 它支持重复支付,支持ExpressCheckout支付。
  • 所有可用的PayPal API方法都封装在属于方法中。
  • 有据可查
票数 1
EN

Stack Overflow用户

发布于 2020-12-15 12:02:32

这是我的Pay Pal REST代码。

代码语言:javascript
复制
        //Request Perms
        $cardtype = $request->cardtype;
        $account_number = $request->cardnumber;
        $expire_date =$request->expire_date;
        $cvv = $request->cvv;
        $plan_id =$request->plan_id;
        $amount = $request->amount;
        $userid = $request->user_id;
        $payment_type = $request->plan_type;
         
       //Genrate tokens
        $ch = curl_init();
        $clientId ='Your Client ID';
        $clientSecret= 'Your Secret ID';
        //you get Clientid and clientSecret  
           https://developer.paypal.com/developer/applications
        curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$clientSecret);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

        $result = curl_exec($ch);

        if(empty($result))die("Error: No response.");
        else
        {
            $json = json_decode($result);
        }
        curl_close($ch);
                              
        $product_id = '';
         //you can create payment plan this link 
           https://www.sandbox.paypal.com/billing/plans

        if ($plan_id == 1) {
            $product_id = 'your plan id';
        }elseif ($plan_id == 2) {
            $product_id = 'your plan id'; 
        }
         
            $ch = curl_init();

                $payment_data = '{
                   "plan_id":"'.$product_id.'",
                   "start_time":"'.gmdate("Y-m-d\TH:i:s\Z",strtotime("+1 day")).'",
                   "shipping_amount":{
                      "currency_code":"USD",
                      "value":"'.$amount.'"
                   },
                   "subscriber":{
                      "name":{
                         "given_name":"",
                         "surname":""
                      },
                      "email_address":"'.$users->email.'",
                      "shipping_address":{
                         "name":{
                            "full_name":""
                         },
                         "address":{
                            "address_line_1":"",
                            "address_line_2":"",
                            "admin_area_2":"",
                            "admin_area_1":"",
                            "postal_code":"",
                            "country_code":"US"
                         }
                      },
                      "payment_source":{
                         "card":{
                            "number":"'.$account_number.'",
                            "expiry":"'. $expiry_date.'",
                            "security_code":"'.$cvv.'",
                            "name":"",
                            "billing_address":{
                               "address_line_1":"",
                               "address_line_2":"",
                               "admin_area_1":"",
                               "admin_area_2":"",
                               "postal_code":"",
                               "country_code":"US"
                            }
                         }
                      }
                   }
                }';

        curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/billing/subscriptions');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payment_data);
        $headers = array();
        $headers[] = 'Accept: application/json';
        $headers[] = 'Authorization: Bearer '.$json->access_token.'';
        $headers[] = 'Paypal-Request-Id: SUBSCRIPTION-'. rand() .'';
        $headers[] = 'Prefer: return=representation';
        $headers[] = 'Content-Type: application/json';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);    
        $payment_id = json_decode($result);
        $data =$headers[2];    
        $subid = substr($data, strpos($data, ":") + 2);

       //save data in database
        $payment = new Subscription(); 
        $payment->userid=$userid; 
        $payment->plan_id=$plan_id;    
        $payment->price=$amount;
        $payment->sub_id=$subid;
        $payment->transaction_id=$payment_id->id;
        $payment->payment_type='Paypal';  
        $payment->charge=$paypal_charge;
        $payment->plan_type=$plan_type;
        $payment->subscription_startdate= $subscription_startdate;
        $payment->subscription_enddate= $subscription_enddate;
        $payment->subscription_status= 'active';
        $payment->save();

        return response()->json(['status' => true,'message'=>'Payment has been successfully Done','data'=>$payment]);

对我来说很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26390065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档