fix(medusa, medusa-payment-paypal): Add missing data in Payment Collection input (#3010)
This commit is contained in:
1 parent
8221e089b8
commit
142c8aa70f
8 files changed
+140
-21
No files matched your search
@@ -30,9 +30,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "cross-env NODE_ENV=production yarn run build",
|
||||
"build": "babel src -d . --ignore **/__tests__",
|
||||
"watch": "babel -w src --out-dir . --ignore **/__tests__",
|
||||
"test": "jest --passWithNoTests"
|
||||
"build": "babel src -d . --ignore **/(__tests__|__mocks__)",
|
||||
"watch": "babel -w src --out-dir . --ignore **/(__tests__|__mocks__)",
|
||||
"test": "jest --passWithNoTests src/**"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"medusa-interfaces": "1.3.3"
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import PayPalProviderService from "../paypal-provider"
|
||||
import {
|
||||
PayPalMock,
|
||||
PayPalClientMock,
|
||||
} from "../../__mocks__/@paypal/checkout-server-sdk"
|
||||
import { PayPalClientMock, PayPalMock, } from "../../__mocks__/@paypal/checkout-server-sdk"
|
||||
|
||||
const TotalsServiceMock = {
|
||||
getTotal: jest.fn().mockImplementation((c) => c.total),
|
||||
@@ -65,6 +62,40 @@ describe("PaypalProviderService", () => {
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
|
||||
it("creates paypal order using new API", async () => {
|
||||
result = await paypalProviderService.createPayment({
|
||||
id: "",
|
||||
region_id: "fr",
|
||||
total: 1000,
|
||||
resource_id: "resource_id"
|
||||
})
|
||||
|
||||
expect(PayPalMock.orders.OrdersCreateRequest).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
order: true,
|
||||
body: {
|
||||
intent: "AUTHORIZE",
|
||||
application_context: {
|
||||
shipping_preference: "NO_SHIPPING",
|
||||
},
|
||||
purchase_units: [
|
||||
{
|
||||
custom_id: "resource_id",
|
||||
amount: {
|
||||
currency_code: "EUR",
|
||||
value: "10.00",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrievePayment", () => {
|
||||
@@ -140,6 +171,41 @@ describe("PaypalProviderService", () => {
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
|
||||
it("updates paypal order using new API", async () => {
|
||||
result = await paypalProviderService.updatePayment(
|
||||
{ id: "test" },
|
||||
{
|
||||
id: "",
|
||||
region_id: "fr",
|
||||
total: 1000,
|
||||
resource_id: "resource_id"
|
||||
}
|
||||
)
|
||||
|
||||
expect(PayPalMock.orders.OrdersPatchRequest).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalMock.orders.OrdersPatchRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
order: true,
|
||||
body: [
|
||||
{
|
||||
op: "replace",
|
||||
path: "/purchase_units/@reference_id=='default'",
|
||||
value: {
|
||||
amount: {
|
||||
currency_code: "EUR",
|
||||
value: "10.00",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("capturePayment", () => {
|
||||
|
||||
@@ -88,10 +88,10 @@ class PayPalProviderService extends PaymentService {
|
||||
* @returns {object} the data to be stored with the payment session.
|
||||
*/
|
||||
async createPayment(cart) {
|
||||
const { region_id } = cart
|
||||
const { region_id, id, resource_id, total } = cart
|
||||
const { currency_code } = await this.regionService_.retrieve(region_id)
|
||||
|
||||
const amount = cart.total
|
||||
const amount = total
|
||||
|
||||
const request = new PayPal.orders.OrdersCreateRequest()
|
||||
request.requestBody({
|
||||
@@ -101,7 +101,7 @@ class PayPalProviderService extends PaymentService {
|
||||
},
|
||||
purchase_units: [
|
||||
{
|
||||
custom_id: cart.id,
|
||||
custom_id: resource_id ?? id,
|
||||
amount: {
|
||||
currency_code: currency_code.toUpperCase(),
|
||||
value: roundToTwo(
|
||||
@@ -216,7 +216,7 @@ class PayPalProviderService extends PaymentService {
|
||||
*/
|
||||
async updatePayment(sessionData, cart) {
|
||||
try {
|
||||
const { region_id } = cart
|
||||
const { region_id, total } = cart
|
||||
const { currency_code } = await this.regionService_.retrieve(region_id)
|
||||
|
||||
const request = new PayPal.orders.OrdersPatchRequest(sessionData.id)
|
||||
@@ -228,7 +228,7 @@ class PayPalProviderService extends PaymentService {
|
||||
amount: {
|
||||
currency_code: currency_code.toUpperCase(),
|
||||
value: roundToTwo(
|
||||
humanizeAmount(cart.total, currency_code),
|
||||
humanizeAmount(total, currency_code),
|
||||
currency_code
|
||||
),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user