2017-02-15 9 views
1

みなさんこんにちは皆さんは、お支払いプランを承認した後に、お支払い契約ID(BAID)の場所を混乱させています。ここで、お支払い契約IDを確認してからご利用ください。

REST-API私が契約を締結した後、この

これまでにPayPalのリターンを使用しました。

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'); 

答えて

1

ときはい、契約を実行した後、戻りオブジェクト内のIDがします後で契約に関する情報を参照するために使用される請求契約IDとすることができる。

次のような例があります。https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/billing/ExecuteAgreement.php

+0

Paypal-REST APIには参照取引がありますか?私はそれを見つけるように見えない。この機能を使用する予定ですhttps://developer.paypal.com/docs/classic/api/merchant/DoReferenceTransaction_API_Operation_NVP/ –

+0

はい、料金プラン(https://developer.paypal.com)をご覧ください/ docs/integration/direct/billing-plans /)と請求契約(https://developer.paypal.com/docs/integration/direct/billing-agreements/)を参照してください。請求プランはサブスクリプションのアーキテクチャーを設定し、ユーザーまたはユーザーを請求プランの詳細 –

+0

にバインドします。私は2人でしたが、https://github.com/paypal/PayPal-PHPの人に尋ねました-SDKと彼らはそれが存在しないと言った。私は自分の問題を解決するために別の方法を強制されます。ありがとう –

関連する問題