invalid keys: card Number, cvv, expiration Month, expiration Year in braintree method - php

I'm trying to create a card token by using Braintree with language of PHP
$gateway = new Braintree\Gateway([
'environment' => 'sandbox',
'merchantId' => 'your_merchantId',
'publicKey' => 'publicKey',
'privateKey' => 'privateKey'
]);
$clientToken = $gateway->clientToken()->generate();
$nonce = $gateway->paymentMethodNonce()->create($clientToken, [
'cardNumber' => '2223000048400011',
'expirationMonth' => '05',
'expirationYear' => '2023',
'cvv' => '321'
]);
$cardToken = $nonce->paymentMethodNonce->nonce;
print_r($cardToken);
exit;
In this code, I have replaced my all required key from Braintree.
Then I'm trying to create a card token by the method of payment nonce but am not able to create a token
Please help me or suggest how to create this token.

Related

Error SHARED_VIEW_USER_LACKS_PERMISSION on DocuSign\eSign\Model\RecipientViewRequest

My scenario would be this flow in my application: Register > Sign Document > Return to Finish Page.
The user register on my application and he need to sign a document to finish his registration. He is not a DocuSign user. At the moment all my tests are at the Sandbox environment.
The envelope creation works great. If I don't use the client_user_id it sends the email for signing. But I need to use the client_user_id to use the embedded signing and get the URL for next step.
When I try to to get the URL of the envelope, I receive the following error:
errorCode: SHARED_VIEW_USER_LACKS_PERMISSION
message: User lacks shared permission to envelope. Only a user with shared access to the envelope may perform the requested operation.
Here is the code I'm using on my PHP application to try to get the URL of the recent created envelope:
$envelope = $this->docusignlib->create_document_for_signing($user, $file);
$result = $this->docusignlib->get_url_document($user, $envelope['envelope_id'], $return_url);
public function create_document_for_signing($user, $file)
{
# Document
$document = new DocuSign\eSign\Model\Document([
'document_base64' => base64_encode(file_get_contents($file)),
'name' => 'Document name',
'file_extension' => 'pdf',
'document_id' => '1'
]);
# Sign Here Position
$signHere = new DocuSign\eSign\Model\SignHere([
'document_id' => '1', 'page_number' => '2', 'recipient_id' => '1',
'tab_label' => 'Sign here', 'x_position' => '100', 'y_position' => '720'
]);
# The signer object
$signer = new DocuSign\eSign\Model\Signer([
'email' => $user->user_email,
'name' => $user->user_name,
'recipient_id' => "1",
'client_user_id' => $user->user_id,
'tabs' => new DocuSign\eSign\Model\Tabs([
'sign_here_tabs' => [$signHere]
])
]);
# Next, create the top level envelope definition and populate it.
$envelopeDefinition = new DocuSign\eSign\Model\EnvelopeDefinition([
'email_subject' => "Email subject",
'documents' => [$document],
'recipients' => new DocuSign\eSign\Model\Recipients(['signers' => [$signer]]),
'status' => "sent"
]);
$config = new DocuSign\eSign\Configuration();
$config->setHost($this->api);
$config->addDefaultHeader("Authorization", "Bearer " . $this->accessToken);
$apiClient = new DocuSign\eSign\Client\ApiClient($config);
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
return $envelopeApi->createEnvelope($this->accountId, $envelopeDefinition);
}
public function get_url_document($user, $envelopeId, $returnUrl)
{
$recipientViewRequest = new DocuSign\eSign\Model\RecipientViewRequest([
'user_name' => $user->user_name,
'email' => $user->user_email,
"recipient_id" => "1",
"client_user_id" => $user->user_id,
"authentication_method" => "email",
"return_url" => $returnUrl
]);
$config = new DocuSign\eSign\Configuration();
$config->setHost($this->api);
$config->addDefaultHeader("Authorization", "Bearer " . $this->accessToken);
$apiClient = new DocuSign\eSign\Client\ApiClient($config);
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
return $envelopeApi->createEnvelopeRecipientSharedView($this->accountId, $envelopeId, $recipientViewRequest);
}
I couldn't find ANYTHING related to this error on the documentation and I checked all the permissions and everything seems ok. I'm using the admin user of my demoaccount. Any ideas what I'm doing wrong here?
Thanks!
SHARED_VIEW_USER_LACKS_PERMISSION is about the user and the account. You may want to try a different account and/or a new envelope. I would also ensure that you are making API call to demo.docusign.net URL and not www.docusign.net since you are still in demo/sandbox.
The accessToken should match the account and if you're using the token generator, it's the account that you used when token generator prompted you to log in.

PARTNER_AUTHENTICATION_FAILED after succesfull geting access token using JWT

I am trying to establish connection between my Application and DocuSign Sandbox.
I'am using JWT Authorization.
I have Integration key with RSA private key generated.
I have user to impersonate with GUID and consent aquired
I call https://account-d.docusign.com/oauth/token with proper data which response with success and give me back Access token
Everything works well until this moment.
I've downloaded library for PHP "docusign/esign-client"
and used this fragment of code:
$recipientId = uniqid(5);
$clientUserId = uniqid(5);
$document = new Document([
'document_base64' => $base64FileContent,
'name' => 'Application Form',
'file_extension' => 'pdf',
'document_id' => '1'
]);
$signer = new Signer([
'email' => $email,
'name' => $name,
'recipient_id' => $recipientId,
'routing_order' => "1",
'client_user_id' => $clientUserId,
]);
$signHere = new SignHere([
'document_id' => '1', 'page_number' => '3', 'recipient_id' => $recipientId,
'tab_label' => 'SignHereTab', 'x_position' => '195', 'y_position' => '147'
]);
$signer->setTabs(new Tabs(['sign_here_tabs' => [$signHere]]));
$envelopeDefinition = new EnvelopeDefinition([
'email_subject' => "Please sign this document",
'documents' => [$document],
'recipients' => new Recipients(['signers' => [$signer]]),
'status' => "sent"
]);
$config = new Configuration();
$config->setHost('https://demo.docusign.net/restapi');
$config->addDefaultHeader("Authorization", "Bearer " . $accessToken);
$config->setAccessToken($accessToken);
$apiClient = new ApiClient($config);
$envelopeApi = new EnvelopesApi($apiClient);
$results = $envelopeApi->createEnvelope($integrationKey, $envelopeDefinition);
The result is an error (400) comes from API with info:
PARTNER_AUTHENTICATION_FAILED
The specified Integrator Key was not found or is disabled. Invalid account specified for user.
It says integration key is wrong but few lines before I used this integration key to generate Access Token with success.
Do you have any idea whats is going wrong ?
Before JWT integrations, I was using different integration key and access token from OAuth Token Generator and it worked fine (this previous key didn't have RSA generated)
Could you guys help me with that issue ?
If any more informations could help to find a solution just let me know and I will update my post.
Thanks for help.
The issue is in this line
$results = $envelopeApi->createEnvelope($integrationKey, $envelopeDefinition);
The first parameter of the createEnvelope method should be the Account ID, not the integrator key.
After you receive the access token, you can make a UserInfo call and pull the account ID from that.

Error : cannot use stripe token more than once

I'm trying to make a monthly subscription plan using the stripe API, but I have an error message saying
Cannot use stripe token more than once
And when I try to remove 'source' => $token I have this error :
The customer must have an active payment source attached.
Here's my code :
require_once('stripe/config.php');
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$customer = \Stripe\Customer::create([
'email' => $email,
'source' => $token,
]);
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxxx");
$product = \Stripe\Product::create([
'name' => 'Abonnement Simple',
'type' => 'service',
]);
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer->id,
"plan" => "simpleNoEngagement"
));
token is required only for creating new customer. Once customer is created, you do not need to send token again. You need to grab customerId in that case.

How to Integration Stripe Payment gateway in laravel?

I followed this link.
I did what it said, but its throwing some error:
FatalErrorException in routes.php line 29:
Class 'Stripe' not found
Line 29 Stripe::setApiKey('sk_test_bDgMM85Y8hWWaRRBrulWNeng');
A few things to check...
Did you install your stripe dependency? composer require stripe/stripe-php
Did you composer dump-auto
Your tutorial link runs stripe from the Routes file. Which is in the global namespace. Are you executing this code from a Controller or from the routes file? If from a controller, then you will need to add a use statement at the top use Stripe\Stripe;
Finally, which version of the https://github.com/stripe/stripe-php package are you using? According to the readme, there is a legacy version and a new version. The new version is has an extra level of nesting and is accessed via Stripe\Stripe and Stripe\Charge:
Legacy Version
Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = Stripe_Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge;
New Version
\Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge;
Here is the thing I did and its working. Hope its work is case of your:
try {
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$customer = \Stripe\Customer::create([
'name' => 'Jenny Rosen',
'email' => 'jenyy#hotmail.co.us',
'address' => [
'line1' => '510 Townsend St',
'postal_code' => '98140',
'city' => 'San Francisco',
'state' => 'CA',
'country' => 'US',
],
]);
\Stripe\Customer::createSource(
$customer->id,
['source' => $request->stripeToken]
);
Stripe\Charge::create ([
"customer" => $customer->id,
"amount" => 100 * 100,
"currency" => "usd",
"description" => "Test payment from stripe.test." ,
]);
Session::flash('success', 'Payment successful!');
} catch (\Exception $ex) {
return $ex->getMessage().' error occured';
Session::flash('error','Payment Failed.');
}
Charge Card
First of All create your stripe account
Stripe Register Page
if you already have Stripe account good to Go
Get API key from your Stripe and Add it to your project .env
Test API Key link : https://dashboard.stripe.com/test/apikeys
Live API Key link : https://dashboard.stripe.com/apikeys
NOTE : You can use API key directly in code but it is not good for security Install stripe-php via composer`
composer require stripe/stripe-php `
IF YOU ARE USING IN API
Setup client and API In code
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
Create token for Payment
$token = $stripe->tokens->create([
'card' => [
'number' => $card_number,
'exp_month' => $exp_month,
'exp_year' => $exp_year,
'cvc' => $cvc,
],
]);
Create Charge
$charge = Stripe\Charge::create ([
"amount" => $request->amount *100,
"currency" => $request->currency,
"source" => $token->id,
"description" => 'payment with credit/debit card'
]);
SECURITY RISK:
We should create token in front-end instead of sending card details on network we should send token
Add JS stripe to your blade file
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
Creating token On front-end using javaScript
Stripe.setPublishableKey($form.data('stripe-publishable-key'));
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
About stripeResponseHandler
This response handler will be a function where Stripe will redirect after success or failure of creating token
function stripeResponseHandler(status, response) {
if (response.error) {
/* token failed to create */
} else {
var token = response['id'];
/* you can send this token to back-end [Laravel Controller] then you need to charge function on backed */
}
}
Hope it will helpful for you

Show billing and shipping information in Paypal Express using Omnipay

I am using Laravel with Omnipay for our ecommerce application. We direct the customers to Paypal to make their purchase. We require shipping and billing information prior to placing an order and we would like that information to continue to Paypal to make it easier for them. However, only the first name and last name are crossing over to Paypal correctly. We can also use email with no issues.
public function postPayment() {
//var_dump(Session::get('shipping_info')); die;
$info = Session::get('shipping_info');
$gateway = Omnipay::gateway('paypal');
//sandbox
$gateway->setUsername('xxxx');
$gateway->setPassword('xxxx');
$gateway->setSignature('xxx');
$gateway->setTestMode('true');
//production
// $gateway->setUsername('xxxx');
// $gateway->setPassword('xxxx');
// $gateway->setSignature('xxxx');
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
// var_dump($card); die;
$response = Omnipay::purchase(
array(
'cancelUrl' => 'http://localhost/public/',
'returnUrl' => 'http://localhost/public/',
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => 'Stuff'
)
)->send();
$response->redirect();
}
According to the docs https://github.com/omnipay/omnipay it should work with no issues. dumping the sessions reveals the correct billing and shipping parameters.
It was just needing a cache refresh.

Categories