Jump to content

paypal DoDirectPayment help


jamesxg1

Recommended Posts

how do i use paypal DoDirectPayment ?,

 

i wanted to intergrade paypal payments in my site but i didnt know how and my mate told me paypal DoDirectPayment is good so i downloaded it from paypal and im 100% baffeled on how to actually use it :S,

 

its SOAP by the way and here is the actually script.

 

<?php
/** DoDirectPayment SOAP example; last modified 08MAY23.
*
*  Process a credit card payment. 
*/

include 'ppsdk_include_path.inc';

require_once 'PayPal.php';
require_once 'PayPal/Profile/Handler/Array.php';
require_once 'PayPal/Profile/API.php';
require_once 'PayPal/Type/DoDirectPaymentRequestType.php';
require_once 'PayPal/Type/DoDirectPaymentRequestDetailsType.php';
require_once 'PayPal/Type/DoDirectPaymentResponseType.php';

$environment = 'sandbox';	// or 'beta-sandbox' or 'live'

//--------------------------------------------------
// PROFILE
//--------------------------------------------------
/**
*                    W A R N I N G
* Do not embed plaintext credentials in your application code.
* Doing so is insecure and against best practices.
*
* Your API credentials must be handled securely. Please consider
* encrypting them for use in any production environment, and ensure
* that only authorized individuals may view or modify them.
*/

$handler = & ProfileHandler_Array::getInstance(array(
            'username' => 'my_api_username',
            'certificateFile' => null,
            'subject' => null,
            'environment' => $environment));

$pid = ProfileHandler::generateID();

$profile = & new APIProfile($pid, $handler);

// Set up your API credentials, PayPal end point, and API version.
$profile->setAPIUsername('my_api_username');
$profile->setAPIPassword('my_api_password');
$profile->setSignature('my_api_signature');
$profile->setCertificateFile('my_cert_file_path');
$profile->setEnvironment($environment);
//--------------------------------------------------

$dp_request =& PayPal::getType('DoDirectPaymentRequestType');
$dp_request->setVersion("51.0");

// Set request-specific fields.
$refund_request->setTransactionId('example_transaction_id', 'iso-8859-1');

$paymentType = 'Authorization';				// or 'Sale'
$firstName = 'customer_first_name';
$lastName = 'customer_last_name';
$creditCardType = 'customer_credit_card_type';
$creditCardNumber = 'customer_credit_card_number';
$expDateMonth = 'cc_expiration_month';
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);

$expDateYear = 'cc_expiration_year';
$cvv2Number = 'cc_cvv2_number';
$address1 = 'customer_address1';
$address2 = 'customer_address2';
$city = 'customer_city';
$state = 'customer_state';
$zip = 'customer_zip';
$country = 'customer_country';				// UNITED_STATES or other valid country
$amount = 'example_payment_amuont';
$currencyID = 'USD';						// or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// setup the DoDirectPayment Request Payment details.
$OrderTotal =& PayPal::getType('BasicAmountType');
$OrderTotal->setattr('currencyID', $currencyID);
$OrderTotal->setval($amount, 'iso-8859-1');

$shipTo =& PayPal::getType('AddressType');
$shipTo->setName($firstName.' '.$lastName);
$shipTo->setStreet1($address1);
$shipTo->setStreet2($address2);
$shipTo->setCityName($city);
$shipTo->setStateOrProvince($state);
$shipTo->setCountry($country);
$shipTo->setPostalCode($zip);

$PaymentDetails =& PayPal::getType('PaymentDetailsType');
$PaymentDetails->setOrderTotal($OrderTotal);
$PaymentDetails->setShipToAddress($shipTo);

// Set up credit card info.
$person_name =& PayPal::getType('PersonNameType');
$person_name->setFirstName($firstName);
$person_name->setLastName($lastName);

$payer =& PayPal::getType('PayerInfoType');
$payer->setPayerName($person_name);
$payer->setPayerCountry($country);
$payer->setAddress($shipTo);

$card_details =& PayPal::getType('CreditCardDetailsType');
$card_details->setCardOwner($payer);
$card_details->setCreditCardType($creditCardType);
$card_details->setCreditCardNumber($creditCardNumber);
$card_details->setExpMonth($padDateMonth);
$card_details->setExpYear($expDateYear);
$card_details->setCVV2($cvv2Number);

$dp_details =& PayPal::getType('DoDirectPaymentRequestDetailsType');
$dp_details->setPaymentDetails($PaymentDetails);
$dp_details->setCreditCard($card_details);
$dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
$dp_details->setPaymentAction($paymentType);

$dp_request->setDoDirectPaymentRequestDetails($dp_details);

$caller =& PayPal::getCallerServices($profile);

// Execute SOAP request.
$response = $caller->DoDirectPayment($dp_request);

switch($response->getAck()) {
case 'Success':
case 'SuccessWithWarning':
        // Extract the response details.
	$tranID = $response->getTransactionID();
	$avsCode = $response->getAVSCode();
	$cvv2 = $response->getCVV2Code();
	$amt = $response->getAmount()->_value;
	$currencyID = $response->getAmount()->getattr('currencyID');
	$amt_display = "$currencyID $amt";
	exit('Direct Payment Completed Successfully: ' . print_r($response, true));

default:
	exit('DoDirectPayment failed: ' . print_r($response, true));
}

?>

Link to comment
Share on other sites

No, just trying to hint that maybe reading the docs that came with the script would be a better / faster way to get help. If you then get stuck then post your specific problem.

 

There's bound to be a simple example in the docs that you can copy / edit.

Link to comment
Share on other sites

No, just trying to hint that maybe reading the docs that came with the script would be a better / faster way to get help. If you then get stuck then post your specific problem.

 

There's bound to be a simple example in the docs that you can copy / edit.

 

agreed, and i did search before i posted (paypal, & google) but i couldnt find bothing :S

Link to comment
Share on other sites

You need to look around more on the paypal website. Download the API integration guide...or something similar to that. I can't give you specific advice on the SOAP method since I use NVP, but I know there is a PDF out there with all the information you need.

 

However, after seeing your other post, I don't think the paypal API is what you're looking for. With the API you collect the credit card information directly on your site, and send all the information to paypal. DoDirectPayment is using credit cards, not paypal accounts. You'll want the express pay API if you're looking to have people pay with paypal only. If you don't really know what you're doing I don't recommend you collect any credit card information on your site. If your security is lax you could be held liable for any losses. Not to mention it will be easier for someone to defraud you. It's a good way to lose a lot of money, and it's a lot more complicated than a simple buy it now button.

 

Stick with the IPN for what you're trying to do. But you should be able to find all the information you need on the paypal API in the developer section of their website. In fact, here's a link directly to the documentation: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_documentation

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.