我已经制作了一个购物车,在退房时将产品详细信息和数量/总金额发送给Paypal。我使用的是Laravel 4和Omnipay Paypal插件(Paypal_Express)。我可以使用' setItems'发送产品详细信息。功能,我现在希望用我的用户的详细信息预先填写Paypal摘要页面上的信用卡字段。
我在THIS之类的其他SO帖子中看到其他人使用creditCard函数将详细信息传递到Paypal摘要信用卡信息页面。
我的问题:1)您是否需要使用Paypal_Pro才能获得creditCard功能?
我尝试(call_user_func_array() expects parameter 1 to be a valid callback, class 'Omnipay\Common\GatewayFactory' does not have a method 'creditCard'
)时收到此错误。
我不想输入所有信用卡详细信息 - 只需输入用户的姓名,地址等即可加快处理速度...
此外,我尝试更改为Paypal_Pro,但它没有工作。 (与上面相同的错误)我在支付控制器中更改了配置和网关。
2)如何将PayPal_Express更改为PayPay_Pro?
我的代码:
public function postPayment() {
$cart = Session::get('cart');
$allProducts = [];
foreach($cart->aContents as $productID=>$quantity){
$product = Product::find($productID);
// get the product id
// load the product from the id
// store data in the allProduct array
$allProducts[] = array('name' => $product->name, 'quantity' => $quantity, 'price'=> $product->price);
}
$cardInput = array(
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'zip' => Input::get('zip'),
'email' => Input::get('email')
);
$card = Omnipay::creditCard($cardInput);
$params = array(
'cancelUrl' => \URL::to('cancel_order'),
'returnUrl' => \URL::to('payment_success'),
'amount' => Input::get('price'),
'currency' => Input::get('currency'),
'card' => $card,
);
Session::put('params', $params);
Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('tjmusicmanagement-facilitator_api1.gmail.com');
$gateway->setPassword('K2LWQVP2L8472BPY');
$gateway->setSignature('AwTOuAJWzCkdc5PldYeiz.l3iy5UAwOucYW6EFLLA9zUQqXaWyEGbebq');
$gateway->setTestMode(true);
$gateway->setLogoImageUrl(URL::to('images/logoSmall.png'));
$response = $gateway->purchase($params)->setItems($allProducts)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
}
并且点燃的\ laravel-omnipay \ config.php也没有改变(尽管我确实试过更改驱动程序)
返回数组(
// The default gateway to use
'default' => 'paypal',
// Add in each gateway here
'gateways' => array(
'paypal' => array(
'driver' => 'PayPal_Express',
'options' => array(
'solutionType' => '',
'landingPage' => '',
'headerImageUrl' => ''
)
)
)
);
谢谢你的帮助!!
编辑:这是我的getSuccessPayment函数,我希望从paypal获得用户paypal详细信息(只是名称和地址等)。但是我如何以及在何处指明这一点?
public function getSuccessPayment()
{
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('lillyloverofwar-facilitator_api1.gmail.com');
$gateway->setPassword('U6LM3SG2MNCA3QE2');
$gateway->setSignature('AJVP9tUtdotIeVt82RpcG7n9ld-tAdCG1Ramb1u8yZECHhSpiXc0BO04');
$gateway->setTestMode(true);
$params = Session::get('params');
$response = $gateway->completePurchase($params)->send();
$paypalResponse = $response->getData(); // this is the raw response object
if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
// return View::make('successfulPayment')->with($params);
// Session::flush();
// Response
// print_r($paypalResponse);
} else {
//Failed transaction
}
// FLUSHING SESSION HERE GETS AN ERROR
// Session::flush();
return View::make('successfulPayment');
}
答案 0 :(得分:1)
1)我在尝试时遇到此错误(call_user_func_array()期望参数1是有效的回调,类'Omnipay \ Common \ GatewayFactory'没有方法'creditCard'。)
您不能在PayPal Express网关上使用信用卡,只能在Pro或REST上使用。我建议您使用REST网关而不是Pro网关(REST取代Pro并具有更多功能)。
我不想输入所有信用卡详细信息 - 只需输入用户姓名,地址等加快处理速度......
如果您使用PayPal Express,则无需这样做,因为PayPal会在用户完成PayPal登录流程并授权交易后为您提供必要的详细信息。
此外,我尝试更改为Paypal_Pro,但它无效。 (与上面相同的错误)我在支付控制器中更改了配置和网关。
2)如何将PayPal_Express更改为PayPay_Pro?
我建议您查看我的omnipay-paypal网关的分支https://github.com/delatbabel/omnipay-paypal - 在accept-paypal-payments分支上还有其他提交(作为PR发送到主存储库但未合并)还有其他功能,例如使用REST网关进行信用卡或PayPal购买,以及其他API文档,包括有关如何使用REST网关的代码示例。
以下是使用Rest网关进行信用卡购买交易的代码示例:
// Create a gateway for the PayPal RestGateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('RestGateway');
// Initialise the gateway
$gateway->initialize(array(
'clientId' => 'MyPayPalClientId',
'secret' => 'MyPayPalSecret',
'testMode' => true, // Or false when you are ready for live transactions
));
// Create a credit card object
// DO NOT USE THESE CARD VALUES -- substitute your own
// see the documentation in the class header.
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '01',
'expiryYear' => '2020',
'cvv' => '123',
'billingAddress1' => '1 Scrubby Creek Road',
'billingCountry' => 'AU',
'billingCity' => 'Scrubby Creek',
'billingPostcode' => '4999',
'billingState' => 'QLD',
));
// Do a purchase transaction on the gateway
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'AUD',
'description' => 'This is a test purchase transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
$sale_id = $response->getTransactionReference();
echo "Transaction reference = " . $sale_id . "\n";
}