Omnipay Stripe payment validation error with default example - laravel

According to the documentation, this is the example code I used to make the payment.
$paymentMethod = $_POST['paymentMethodId'];
$response = $gateway->authorize([
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'paymentMethod' => $paymentMethod,
'returnUrl' => $completePaymentUrl,
'confirm' => true,
])->send();
But it gives me a validation error:
How can I solve this?

Related

How to use laravel cashier charge with `withMetaData` and `create`

I am new to laravel cashier, and I am stuck here.
For my games, users can subscribe. I have 3 subscription methods.
Monthly
Yearly
One-time.
For monthly and Yearly subscriptions, I have used the below code and it works perfectly.
$subscription = $user->newSubscription($subscriptionName, $plan->stripe_id)->withMetaData(['game' => $game->name])->create(null, [
'email' => $user->email,
'name' => $user->name,
['metadata' => ['game' => $game->name]],
], $subscriptionOptions);
But for the one-time subscription, I have used the below code
$subscription = $user->charge(2500, 'pm_1IpuT.....')->withMetaData(['game' => $game->name])->create(null, [
'email' => $user->email,
'name' => $user->name,
['metadata' => ['game' => $game->name]],
], $subscriptionOptions);
for this, I am and getting the below error
Error
Call to undefined method Laravel\Cashier\Payment::withMetaData()
Can anyone help to solve this?
As they mention here you pass the metadata as a third argument in the charge method
$user->charge(100, $paymentMethod, [
'custom_option' => $value,
]);
so in your example, you need to edit it like this
$subscription = $user->charge(2500, 'pm_1IpuT.....', [
'metadata' => [
'game' => $game->name,
'email' => $user->email,
'name' => $user->name,
]
]);
for more additional data to pass check stripe docs

can i use stripe checkout with destination charges?

I'm wondering if there is any way to charge some kind of fee on transactions using the new Stripe Checkout system. In this particular instance I am using Laravel 8 with Livewire. In my component I have a function tied to a button called setStripeSession.
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'Custom Media',
],
'unit_amount' => $this->toPennies($price),
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => 'http://e68ec3e6b8b2.ngrok.io/',
'cancel_url' => 'http://e68ec3e6b8b2.ngrok.io/',
],['stripe_account_id'=>$this->stripe_account_id]);
$this->stripe_session_id = $session->id;
Message::where('id',$message_id)->update(['stripe_session_id'=>$this->stripe_session_id ]);
$this->emit('PayonStripe',['ssid'=>$session->id]);
}
I imagined adding something like the below code but the variables are not recognized by the stripe API during the rquest.
'transfer_data' => [
'destination' => '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
],
Yes! You can set these within the payment_intent_data parameter:
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [...],
'mode' => 'payment',
'success_url' => 'http://example.com/success',
'cancel_url' => 'http://example.com/cancel',
'payment_intent_data' => [
'application_fee_amount' => 100, // optional
'transfer_data' => [
'destination' => 'acct_123',
],
],
]);
A number of parameters are exposed this way in Checkout, such as metadata for the payment intent and similar data for subscription mode under subscription_data.

laravel wont set header during gopay payment integration

I have a problem with payment integration to my laravel project. It is a GOPAY REST API.
It should by default set request headers with Accept, Content-type and Authorization where the token is stored. Problem is that it doesnt set my request headers. I used the same thing in a normal script which included the SDK and it worked correctly. However in my laravel project it just doesnt work. The SDK uses Curl to set headers and i think there is somewhere the problem.
I also didnt find any similar problem, and i definitely didnt google anyone who integrated GoPay into Laravel.
Pay method in my controller
//minimal configuration
$gopay = GoPay\payments([
'goid' => '8583340073',
'clientId' => '1162442589',
'clientSecret' => 'eDxNQ3ru',
'isProductionMode' => false,
'scope' => GoPay\Definition\TokenScope::ALL,
'language' => GoPay\Definition\Language::CZECH],
['logger' => new GoPay\Http\Log\PrintHttpRequest()]);
$response = $gopay->createPayment([
'payer' => [
'default_payment_instrument' => PaymentInstrument::BANK_ACCOUNT,
'allowed_payment_instruments' => [PaymentInstrument::BANK_ACCOUNT],
'default_swift' => BankSwiftCode::FIO_BANKA,
'allowed_swifts' => [BankSwiftCode::FIO_BANKA, BankSwiftCode::MBANK],
'contact' => [
'first_name' => 'Zbynek',
'last_name' => 'Zak',
'email' => 'test#test.cz',
'phone_number' => '+420777456123',
'city' => 'C.Budejovice',
'street' => 'Plana 67',
'postal_code' => '373 01',
'country_code' => 'CZE',
],
],
'target' => ['type' => 'ACCOUNT', 'goid' => '8583340073'],
'currency' => Currency::CZECH_CROWNS,
'order_number' => '001',
'order_description' => 'pojisteni01',
'items' => [
['name' => 'item01', 'amount' => 50],
['name' => 'item02', 'amount' => 100],
],
'recurrence' => [
'recurrence_cycle' => Recurrence::DAILY,
'recurrence_period' => "7",
'recurrence_date_to' => '2016-12-31'
],
'additional_params' => [
array('name' => 'invoicenumber', 'value' => '2015001003')
],
'callback' => [
'return_url' => 'http://www.hume.cz/public',
'notification_url' => 'http://www.hume.cz/public'
]
]);
I think that somehow laravel changes the headers and doesnt allow the SDK to do it. If you know anything please help me. If you need any extra information, please just ask.
Thank you very much!!
There is a package for handling GoPay payments with Laravel. Install, update config with your credentials and start using GoPay facade to createPayment or another function from official SDK.
I have eshop in production with this my own package and everything works fine.
https://github.com/hazestudio/laravel-gopay-sdk

Integrate Multi-Channel Sales With Magento API

Looking for advice on the sequence of Magento API calls necessary to implement this business process:
An inventory item (either physical or virtual/digital) is made available by the seller via an external channel (not the regular web storefront).
A customer initiates a payment directly to me without going through the Magento cart / checkout flow (can I lookup sales tax at this point?)
After the payment has been made, I want to trigger Magento post-processing logic to record the sale, manage inventory, etc.
For physical goods, I want to trigger Magento fulfillment logic to occur to create the shipment, etc.
I'm aware of the SOAP API, I'm looking for help to understand which actions need to be taken along the way to enact this process.
Here is very basic example how Magento API can be used for your case:
Connect to Magento via API
$user = 'apiUser'; $password = 'apiKey';
$proxy = new SoapClient('http://your_magento_host.com/api/v2_soap/?wsdl');
$sessionId = $proxy->login($user, $password);
Create or select customer
// Create customer
$customerList = $proxy->customerCustomerCreate($sessionId, array( 'email' => 'customer#gmail.com', 'firstname' => 'Will', 'lastname' => 'Smith', 'password' => 'qwerty', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1 ));
$customer = (array) $customerList[0];
$customer['mode'] = 'customer';
// Or select existing customer (by email)
$filter = array(
'complex_filter' => array(
array(
'key' => 'email',
'value' => array('key' => 'in', 'value' => 'customer#gmail.com')
)
) );
$customerList = $proxy->customerCustomerList($sessionId, $filter);
$customer = (array) $customerList[0];
$customer['mode'] = 'customer';
Create cart
$cartId = $proxy->shoppingCartCreate($sessionId, 1);
$proxy->shoppingCartCustomerSet($sessionId, $cartId, $customer);
Select product (by sku)
$filter = array(
'complex_filter' => array(
array(
'key' => 'sku',
'value' => array('key' => 'in', 'value' => 'T-SHIRT001')
)
) );
$productList = $proxy->catalogProductList($sessionId, $filter);
$product = (array) $productList[0];
$product['qty'] = 1;
Add product to cart
$proxy->shoppingCartProductAdd($sessionId, $cartId, array($product));
Set billing/shipping address. You should add this addresses to customer if you just create it before.
$address = array(
array(
'mode' => 'shipping',
'firstname' => $customer['firstname'],
'lastname' => $customer['lastname'],
'street' => 'street address',
'city' => 'city',
'region' => 'region',
'telephone' => 'phone number',
'postcode' => 'postcode',
'country_id' => 'country ID',
'is_default_shipping' => 0,
'is_default_billing' => 0
),
array(
'mode' => 'billing',
'firstname' => $customer['firstname'],
'lastname' => $customer['lastname'],
'street' => 'street address',
'city' => 'city',
'region' => 'region',
'telephone' => 'phone number',
'postcode' => 'postcode',
'country_id' => 'country ID',
'is_default_shipping' => 0,
'is_default_billing' => 0
),
);
$proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address);
Set shipping mathod
$proxy->shoppingCartShippingMethod($sessionId, $cartId, 'flatrate_flatrate');
Set payment method.
$paymentMethod = array(
'po_number' => null,
'method' => 'checkmo',
'cc_cid' => null,
'cc_owner' => null,
'cc_number' => null,
'cc_type' => null,
'cc_exp_year' => null,
'cc_exp_month' => null
);
$proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod);
Place order
$orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null);
Now check Sales->Orders in Magento admin area and you'll see new order.
More details here: http://www.magentocommerce.com/api/soap/introduction.html
Yes, you can catch information about Tax:
1) Without order saving. Step 9:
$result = $proxy->shoppingCartTotals($sessionId, $cartId);<br>
var_dump($result);
You'll see array of subtotal, taxes, discounts and total.
2) With order saving. Step 10:
$result = $proxy->salesOrderInfo($sessionId, $orderId);<br>
var_dump($result);
// cancel order<br>
$result = $proxy->salesOrderCancel($sessionId, $orderId);
More information about used API calls here:
http://www.magentocommerce.com/api/soap/checkout/cart/cart.totals.html
http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.info.html
http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.cancel.html

cakephp notempty and unique validation on field

I am working with cakephp. I need to add three validation on email field. First validation if email not given, second for valid email address, third if email address is given then it should be unique. Because its a signup form.
How I have add three validations on one field I try with the following code but it did not work for me.
public $validate = array(
'email' => array(
'email' => array(
'rule' => array('email'),
'message' => 'Invalid email address',
'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
)
),
'email' => array(
'rule' => 'isUnique',
'message' => 'Email already registered'
)
);
You have two identical indexes 'email' which PHP won't allow you. Change to something like:-
array(
'email' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Provide an email address'
),
'validEmailRule' => array(
'rule' => array('email'),
'message' => 'Invalid email address'
),
'uniqueEmailRule' => array(
'rule' => 'isUnique',
'message' => 'Email already registered'
)
)
);
Otherwise only one of your rules will be used.
As of cakephp 3.0 in the entities table it should look something like this
namespace App\Model\Table;
public function validationDefault($validator)
{
$validator
->email('email')
->add('email', 'email', [
'rule' => [$this, 'isUnique'],
'message' => __('Email already registered')
])
->requirePresence('email', 'create')
->notEmpty('email', 'Email is Required', function( $context ){
if(isset($context['data']['role_id']) && $context['data']['role_id'] != 4){
return true;
}
return false;
});
return $validator;
}
}
function isUnique($email){
$user = $this->find('all')
->where([
'Users.email' => $email,
])
->first();
if($user){
return false;
}
return true;
}
What version of Cakephp do you use?
Because I think if you use 2.3, it should be:
public $validate = array( 'email' => 'email' );
with the field email in your SQL table set as a primary key.

Resources